﻿#include "minigui_test.h"

#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/ctrl/static.h>
#include <minigui/ctrl/button.h>
#include <minigui/ctrl/edit.h>
#include <minigui/ctrl/scrollview.h>
#include <minigui/ctrl/scrollbar.h>
#include <mgi/mgi.h>
//#include <mgutils/mgutils.h>

//#include <minigui/mgext.h>

//#include  <minigui/gdi.h>
//#include "minigui_api.h"
//#include "gbk_unicode.h"









static int HelloWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
	char s8Utf8[64];

	snprintf(s8Utf8, sizeof(s8Utf8), "你好世界你好");

    switch (message) {
/*
		case MSG_NCCREATE:
			QLOG(TDBG, "创建主界面，初始化字体\n");

			pstFont = CreateLogFont("ttf", "simhei", "UTF-8",FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN,FONT_FLIP_NIL, FONT_OTHER_NIL,
							FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,48,0);
			break;
*/
        case MSG_PAINT:
           	hdc = BeginPaint(hWnd);
			TextOut(hdc, 40, 40, s8Utf8);

            EndPaint (hWnd, hdc);
        	return 0;
        case MSG_CLOSE:
			QLOG(TDBG, "结束主界面\n");
			//DestroyLogFont(pstFont);
            DestroyMainWindow (hWnd);
            PostQuitMessage (hWnd);
            return 0;
    }

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}

int MINI_TEST_HelloWorld(void)
{
	MSG Msg;
	HWND hMainWnd;
	MAINWINCREATE CreateInfo;
	unsigned char bRet;



	CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
	//CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER;
	CreateInfo.dwStyle = WS_BORDER;
	//CreateInfo.dwExStyle = WS_EX_NONE;
	CreateInfo.dwExStyle = WS_EX_AUTOSECONDARYDC;
	CreateInfo.spCaption = "你好";
	CreateInfo.hMenu = 0;
	CreateInfo.hCursor = GetSystemCursor(0);
	CreateInfo.hIcon = 0;
	CreateInfo.MainWindowProc = HelloWinProc;
	CreateInfo.lx = 15;
	CreateInfo.ty = 0;
	//CreateInfo.rx = MINI_RX;
	//CreateInfo.by = MINI_BY;
	CreateInfo.rx = 420;
	CreateInfo.by = 420;
	//CreateInfo.iBkColor = COLOR_lightwhite;
	CreateInfo.iBkColor = COLOR_transparent;
	//CreateInfo.iBkColor = COLOR_invalid;
	CreateInfo.dwAddData = 0;
	CreateInfo.hHosting = HWND_DESKTOP;

	//hMainWnd = CreateMainWindow (&CreateInfo);
	hMainWnd = CreateMainWindow(&CreateInfo);

	if (hMainWnd == HWND_INVALID)
	return -1;


#if 0
	//GetWindowElementPixelEx (HWND_DESKTOP, HDC hdc, WE_BGC_DESKTOP);

	WINDOW_ELEMENT_ATTR we_attrs;
	SetWindowElementRenderer(HWND_DESKTOP, "123", &we_attrs);

#endif
	bRet = ShowWindow(hMainWnd, SW_SHOW);
	if(FALSE == bRet) {
		QLOG(ERR, "MINI_API_ShowOrHideWindow failed\n");
		return -1;
	} else if(TRUE == bRet) {
		QLOG(TDBG, "成功显示窗口\n");
	}
	ShowWindow(hMainWnd, SW_HIDE);
	ShowWindow(hMainWnd, SW_SHOW);


	while(GetMessage(&Msg, hMainWnd)) {
	        TranslateMessage (&Msg);
	        DispatchMessage (&Msg);
	}
	QLOG(TDBG, "退出窗口\n");

	MainWindowThreadCleanup(hMainWnd);

	return 0;
}



#define IDC_DLGBUTTON 		100
#define IDC_CREATEBUTTON 	101
#define IDC_PROMPTINFO 		200
#define IDC_PROGRESS 		201
#define IDC_BUTTON 			300



static DLGTEMPLATE DlgInitProgress ={
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	120, 150, 400, 130,
	"VAM-CNC 正在进行初始化",
	0, 0,
	3, NULL,
	0
};

static CTRLDATA CtrlInitProgress [] =
{
	{
		"static",
		WS_VISIBLE | SS_SIMPLE,
		10, 10, 380, 16,
		IDC_PROMPTINFO,
		"正在...",
		0
	},
	{
		"progressbar",
		WS_VISIBLE,
		10, 40, 380, 20,
		IDC_PROGRESS,
		NULL,
		0
	},
	{
		"button",
		WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
		170, 70, 60, 25,
		IDOK,
		"确定",
		0
	}
};


/* 定义对话框回调函数 */
static int MINI_TEST_InitDialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	static PLOGFONT pstFont = NULL;
	switch (message) {
		case MSG_INITDIALOG:
			QLOG(TDBG, "收到联接对话框命令 你你好\n");
			pstFont = CreateLogFont("ttf", "simhei", "UTF-8",FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN,FONT_FLIP_NIL, FONT_OTHER_NIL,
							FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,48,0);
			return 1;
		case MSG_COMMAND:
			switch (wParam) {
				case IDOK:
				case IDCANCEL:
					QLOG(TDBG, "收到结束对话框命令\n");
					EndDialog (hDlg, wParam);
			break;
		}
		break;
	}
	return DefaultDialogProc(hDlg, message, wParam, lParam);
}

static int MINI_TEST_InitDialogBox(HWND hWnd)
{
	/* 将对话框模板结构和控件结构数组关联起来 */
	DlgInitProgress.controls = CtrlInitProgress;
	return DialogBoxIndirectParam(&DlgInitProgress, hWnd, MINI_TEST_InitDialogBoxProc, 0L);
}


int MINI_TEST_DialogBoxIndirectParam(void)
{

	HWND hMainWnd;
	MAINWINCREATE CreateInfo;
	int bRet;
	MSG stMsg;


	//CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
	CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER;
	//CreateInfo.dwExStyle = WS_EX_NONE;
	CreateInfo.spCaption = "你好！！测试";
	CreateInfo.hMenu = 0;
	CreateInfo.hCursor = GetSystemCursor (0);
	CreateInfo.hIcon = 0;
	CreateInfo.MainWindowProc = HelloWinProc;
	CreateInfo.lx = 15;
	CreateInfo.ty = 0;
	CreateInfo.rx = MINI_RX;
	CreateInfo.by = MINI_BY;
	CreateInfo.iBkColor = COLOR_lightwhite;
	//CreateInfo.iBkColor = COLOR_darkred;
	CreateInfo.dwAddData = 0;
	CreateInfo.hHosting = HWND_DESKTOP;

	//hMainWnd = CreateMainWindow (&CreateInfo);
	hMainWnd = CreateMainWindow(&CreateInfo);

	if (hMainWnd == HWND_INVALID)
		goto MINI_TEST_DialogBoxIndirectParamErr;



	bRet = ShowWindow(hMainWnd, SW_SHOW);
	if(FALSE == bRet) {
		QLOG(ERR, "MINI_API_ShowOrHideWindow failed\n");
		return -1;
	} else if(TRUE == bRet) {
		QLOG(TDBG, "成功显示窗口\n");
	}
	MINI_TEST_InitDialogBox(hMainWnd);

	while(GetMessage(&stMsg, hMainWnd)) {
	        TranslateMessage (&stMsg);
	        DispatchMessage (&stMsg);
	}
	QLOG(TDBG, "退出窗口\n");

	//MINI_API_EndDialog(s32DialogId, 0);
	MainWindowThreadCleanup(hMainWnd);
	DestroyAllControls(hMainWnd);

	QLOG(TDBG, "退出窗口和对话窗口\n");

	return 0;

MINI_TEST_DialogBoxIndirectParamErr:

	MainWindowThreadCleanup(hMainWnd);

	return -1;




}





/* 定义对话框模板 */
static DLGTEMPLATE DlgBoxInputLen =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	120, 150, 400, 160,
	"请输入长度",
	0, 0,
	4, NULL,
	0
};
#define IDC_SIZE_MM 100
#define IDC_SIZE_INCH 110
/*
* 该对话框一共含有 4 个控件，分别用于显示提示信息、MiniGUI 3.0 编程指南
Copyright © by the Feynman Software. All contents is the property of Feynman Software.
* 用户输入框、显示转换后的长度值以及关闭程序用的“确定”按钮。
*/
static CTRLDATA CtrlInputLen [] =
{
	{
		CTRL_STATIC,
		WS_VISIBLE | SS_SIMPLE,
		10, 10, 380, 18,
		IDC_STATIC,
		"请输入长度（单位：毫米） ",
		0
	},
	{
		CTRL_EDIT,
		WS_VISIBLE | WS_TABSTOP | WS_BORDER,
		10, 40, 380, 24,
		IDC_SIZE_MM,
		NULL,
		0
	},
	{
		CTRL_STATIC,
		WS_VISIBLE | SS_SIMPLE,
		10, 70, 380, 18,
		IDC_SIZE_INCH,
		"相当于 0.00 英寸",
		0
	},
	{
		CTRL_BUTTON,
		WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
		170, 100, 60, 25,
		IDOK,
		"确定",
		0
	}
};

/* 这是输入框的通知回调函数。 */
static void my_notif_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
	/* 当输入框中的值发生变化时，取出值并转换成英寸显示在英寸框中。
	*/
	if (id == IDC_SIZE_MM && nc == EN_CHANGE) {
		char buff [60];
		double len;
		GetWindowText (hwnd, buff, 32);
		len = atof(buff);
		len = len / 25.4;
		sprintf (buff, "相当于 %.5f 英寸", len);
		SetDlgItemText (GetParent (hwnd), IDC_SIZE_INCH, buff);
	}
}



HWND g_hIMEWnd = 0UL;
#define IDC_EDT_ADDR 21100

static HWND sk_ime_hwnd;
static BOOL g_ime_opened = FALSE;
static void edit_notif_proc(HWND hDlg, int id, int nc, DWORD add_data)
{
    IME_TARGET_INFO ime_t_info;
    //edit控件的消息处理函数中打印caret的位置
    GetIMETargetInfo(&ime_t_info);
    printf("ime_t_info.ptCaret: (%d, %d)\n", ime_t_info.ptCaret.x, ime_t_info.ptCaret.y);
}

void notify_ime_status(BOOL);



/* 该对话框的窗口过程 */
static int InputLenDialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
		case MSG_INITDIALOG:
			/* 将通过 DialogBoxIndirectParam 的最后一个参数传递进入的指针
			* 以窗口附加数据的形式保存下来，以便在以后使用。
			*/
			SetWindowAdditionalData (hDlg, lParam);
			/* 设置控件的通知回调函数。
			*/
			SetNotificationCallback(GetDlgItem (hDlg, IDC_SIZE_MM), my_notif_proc);


			//g_hIMEWnd  = hDlg;
			QLOG(TDBG, "初始化键盘输入\n");
			PLOGFONT gb2312_font = CreateLogFontByName("ttf-simhei-rrncnn-0-0-UTF-8");
			if(gb2312_font == NULL) {
				QLOG(TDBG, "字体为空\n");
			}
			SetWindowFont(hDlg, gb2312_font);

            SetNotificationCallback(GetDlgItem(hDlg, IDC_EDT_ADDR), edit_notif_proc);
            sk_ime_hwnd = mgiCreateSoftKeypad(notify_ime_status);
            SetFocusChild(GetDlgItem(hDlg, IDC_EDT_ADDR));
            SetIMEStatus(IME_STATUS_AUTOTRACK, TRUE);
            SetIMEStatus(IME_STATUS_ENCODING, IME_ENCODING_UTF8);
            SetIMEStatus(IME_STATUS_ENABLED, TRUE);
            return 1;

		case MSG_COMMAND:
			switch (wParam) {
				case IDOK:
				{
					char buff [40];
					/* 从输入框中获得数据，并保存在传入的指针中。
					*/
					//double* length = (double*) GetWindowAdditionalData (hDlg);
					GetWindowText (GetDlgItem (hDlg, IDC_SIZE_MM), buff, 32);
					QLOG(TDBG, "接受到输出 [%s]\n", buff);
					//*length = atof (buff);
				}
		case IDCANCEL:
			EndDialog (hDlg, wParam);
			break;
		}
		break;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}

char *pstStr = "请输入长度";

static void InputLenDialogBox (HWND hWnd, double* length)
{








	DlgBoxInputLen.controlnr = sizeof(CtrlInputLen) / sizeof(CtrlInputLen[0]);
	DlgBoxInputLen.controls = CtrlInputLen;

	DialogBoxIndirectParam (&DlgBoxInputLen, hWnd, InputLenDialogBoxProc, (LPARAM)length);
}

int MINI_TEST_InputLenDialogBox()
{

	double length;

	InputLenDialogBox (HWND_DESKTOP, &length);
	/* 把用户在对话框中输入的值打印在终端上。
	*/
	printf ("The length is %.5f mm.\n", length);
	return 0;
}





//高级空间，暂时先不要
#if 0

#define IDC_EDIT 100
#define IDC_SPINBOX 110
/* 用于编辑框的字体。为了取得较好效果，本程序使用了 TrueType 字体 */
static PLOGFONT timefont;
/* 保存老的编辑框窗口过程 */
static WNDPROC old_edit_proc;
/* 本函数根据当前插入符的位置，修改相应的时间单元值 */
static void on_down_up (HWND hwnd, int offset)
{
	char time [10];
	int caretpos;
	int hour, minute, second;
	GetWindowText (hwnd, time, 8);
	caretpos = SendMessage (hwnd, EM_GETCARETPOS, 0, 0);
	hour = atoi (time);
	minute = atoi (time + 3);
	second = atoi (time + 6);
	if (caretpos > 5) { /* change second */
		/* 在秒的位置 */
			second += offset;
		if (second < 0)
			second = 59;
		if (second > 59)
			second = 0;
	}else if (caretpos > 2) { /* change minute */
		/* 在分的位置 */
		minute += offset;
		if (minute < 0)
			minute = 59;
		if (minute > 59)
			minute = 0;
	} else { /* change hour */
		/* 在时的位置 */
		hour += offset;
		if (hour < 0)
			hour = 23;
			if (hour > 23)
				hour = 0;
	}
	/* 将修改后的时间字符串置于编辑框 */
	sprintf (time, "%02d:%02d:%02d", hour, minute, second);
	SetWindowText (hwnd, time);
	/* 恢复插入符位置 */
	SendMessage (hwnd, EM_SETCARETPOS, 0, caretpos);
}

/* 这是编辑框的子类化窗口过程函数 */
static int TimeEditBox (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
	/* 只处理按键消息。下面这些键按下时，调用 on_down_up 函数修改时间值 */
	if (message == MSG_KEYDOWN) {
		switch (wParam) {
		case SCANCODE_CURSORBLOCKUP:
			on_down_up (hwnd, 1);
			return 0;
		case SCANCODE_CURSORBLOCKDOWN:
			on_down_up (hwnd, -1);
			return 0;
		case SCANCODE_PAGEUP:
			on_down_up (hwnd, 10);
			return 0;
		case SCANCODE_PAGEDOWN:
			on_down_up (hwnd, -10);
			return 0;
		case SCANCODE_CURSORBLOCKLEFT:
		case SCANCODE_CURSORBLOCKRIGHT:
			break;
			default:
			return 0;
		}
	}

	/* 忽略下面两个消息，用户只能通过上面的按键进行操作 */
	if (message == MSG_KEYUP || message == MSG_CHAR)
		return 0;
		return (*old_edit_proc) (hwnd, message, wParam, lParam);
}


static int TimeEditorWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
		case MSG_CREATE:
		{
			HWND hwnd;
			HDC hdc;
			HWND timeedit, spin;
			SIZE size;
			/* 建立说明性静态框 */
			hwnd = CreateWindow (CTRL_STATIC,
				"This is a time editor.\n\n"
				"Pressing <Down-Arrow>, <Up-Arrow>, <PgDn>, and <PgUp> keys"
				" when the box has input focus will change the time.\n\n"
				"You can also change the time by clicking the SpinBox.\n",
				WS_CHILD | WS_VISIBLE | SS_LEFT,
				IDC_STATIC, 10, 10, 220, 200, hWnd, 0);

			/* 创建编辑框使用的逻辑字体 */
			timefont = CreateLogFont (NULL, "Arial", "ISO8859-1",
				FONT_WEIGHT_BOOK, FONT_SLANT_ROMAN, FONT_FLIP_NIL,
				FONT_OTHER_NIL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,
				30, 0);

			/* 计算输出时间所用的大小和宽度 */
			hdc = GetClientDC (hWnd);
			SelectFont (hdc, timefont);
			GetTextExtent (hdc, "00:00:00", -1, &size);
			ReleaseDC (hdc);

			/* 按照计算出的值创建编辑框窗口 */
			timeedit = CreateWindow (CTRL_SLEDIT,
				"00:00:00",
				WS_CHILD | WS_VISIBLE | ES_BASELINE,
				IDC_EDIT,
				40, 220, size.cx + 4, size.cy + 4, hWnd, 0);

			/* 设置编辑框字体 */
			SetWindowFont (timeedit, timefont);
			/* 子类化编辑框 */
			old_edit_proc = SetWindowCallbackProc (timeedit, TimeEditBox);
			/* 创建旋钮控件 */
			spin = CreateWindow (CTRL_SPINBOX,
			"",
			WS_CHILD | WS_VISIBLE,
			IDC_SPINBOX,
			40 + size.cx + 6, 220 + (size.cy - 14) / 2, 0, 0, hWnd, 0);
				/*
				* 将旋钮控件的目标窗口设置为编辑框，这样，
				* 当用户单击旋钮时，将模拟 MSG_KEYDOWN 消息
				* 并发送到编辑框。
				*/
				SendMessage (spin, SPM_SETTARGET, 0, timeedit);
				break;
			}

	case MSG_DESTROY:
		DestroyAllControls (hWnd);
		DestroyLogFont (timefont);
		return 0;
	case MSG_CLOSE:
		DestroyMainWindow (hWnd);
		PostQuitMessage (hWnd);
		return 0;
	}
	return DefaultMainWinProc (hWnd, message, wParam, lParam);
}


static void TimeEditorWinBox (HWND hWnd, double* length)
{
	DlgBoxInputLen.controls = CtrlInputLen;
	DialogBoxIndirectParam(&DlgBoxInputLen, hWnd, TimeEditorWinProc, (LPARAM)length);
}

int MINI_TEST_InputLenDialogBox()
{

	double length;

	TimeEditorWinBox (HWND_DESKTOP, &length);
	/* 把用户在对话框中输入的值打印在终端上。
	*/
	printf ("The length is %.5f mm.\n", length);
	return 0;
}
#endif





/* 定义窗口中要显示的字符串数组 */
static char* strLine[] = {
	"This is the 1st line.",
	"This is the 2nd line.",
	"This is the 3rd line.",
	"This is the 4th line.",
	"This is the 5th line.",
	"This is the 6th line.",
	"This is the 7th line.",
	"This is the 8th line.",
	"This is the 9th line.",
	"This is the 10th line.",
	"This is the 11th line.",
	"This is the 12th line.",
	"This is the 13th line.",
	"This is the 14th line.",
	"This is the 15th line.",
	"This is the 16th line.",
	"This is the 17th line."
};




/* 窗口过程 */
static int ScrollWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
	{
	static int iStart = 0;
	static int iStartPos = 0;
	switch (message) {
	case MSG_CREATE:
		/* 创建插入符 */
		QLOG(TDBG, "创建插入符\n");
		SCROLLINFO si;
		si.nMax = 100;
		si.nMin = 0;
		si.nPage = 10; // 该变量决定了滚动滑块的长度，该长度是由 nPage/(nMax-nMin)的大小决定的
		si.nPos = 0; // 滑块的当前位置，它必须在 nMin 和 nMax 的范围内
		SetScrollInfo (hWnd, SB_HORZ, &si, TRUE);
		SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
		if (!CreateCaret (hWnd, NULL, 8, 14))
			fprintf (stderr, "Create caret error!\n");
		break;
	case MSG_SHOWWINDOW:
		/* 禁止水平滚动条 */
		QLOG(TDBG, "禁止水平滚动条\n");
		EnableScrollBar (hWnd, SB_HORZ, FALSE);
		//EnableScrollBar (hWnd, SB_HORZ, TRUE);
		//EnableScrollBar (hWnd, SB_VERT, TRUE);
		/* 设置垂直滚动条的滚动范围： 0～20 */
		SetScrollRange (hWnd, SB_VERT, 0, 100);
		ShowCaret (hWnd);
		break;
	case MSG_SETFOCUS:
		/* 在获得输入焦点时激活并显示插入符 */
		QLOG(TDBG, "在获得输入焦点时激活并显示插入符\n");
		ActiveCaret (hWnd);
		ShowCaret (hWnd);
		break;
	case MSG_KILLFOCUS:
		/* 在失去输入焦点时隐藏插入符 */
		QLOG(TDBG, "在失去输入焦点时隐藏插入符\n");
		HideCaret (hWnd);
		break;
	case MSG_LBUTTONDOWN:
		/* 鼠标点击时修改插入符的位置 */
		QLOG(TDBG, "鼠标点击时修改插入符的位置\n");
		SetCaretPos (hWnd, LOWORD (lParam), HIWORD (lParam));
		break;
	case MSG_LBUTTONDBLCLK:
		/* 鼠标左键双击时隐藏水平滚动条 */
		QLOG(TDBG, "鼠标左键双击时隐藏水平滚动条\n");
		ShowScrollBar (hWnd, SB_HORZ, FALSE);
		break;
	case MSG_RBUTTONDBLCLK:
		/* 鼠标右键双击时显示水平滚动条 */
		QLOG(TDBG, "鼠标右键双击时显示水平滚动条\n");
		ShowScrollBar (hWnd, SB_HORZ, TRUE);
		break;
	/* 处理水平滚动条 */
	case MSG_HSCROLL:
		QLOG(TDBG, "处理水平滚动条\n");
		if (wParam == SB_LINERIGHT) {
			if (iStartPos < 5) {
				iStartPos++;
			/* 向右滚，每次滚一个系统字符宽度 */
			ScrollWindow (hWnd, -GetSysCharWidth(), 0, NULL, NULL);
			}
		}else if (wParam == SB_LINELEFT) {
			if (iStartPos > 0) {
				iStartPos--;
			/* 向左滚，每次滚一个系统字符宽度 */
			ScrollWindow (hWnd, GetSysCharWidth (), 0, NULL, NULL);
			}
		}
		break;
		/* 处理垂直滚动条 */
	case MSG_VSCROLL:
		QLOG(TDBG, "处理垂直滚动条\n");
		if (wParam == SB_LINEDOWN) {
			if (iStart < 12) {
			iStart ++;
			/* 向上滚，每次滚一个 20 个象素高 */
			ScrollWindow (hWnd, 0, -20, NULL, NULL);
			}
		}else if (wParam == SB_LINEUP) {
			if (iStart > 0) {
			iStart --;
			/* 向下滚，每次滚一个 20 个象素高 */
			ScrollWindow (hWnd, 0, 20, NULL, NULL);
			}
		}
		/* 更新滚动条位置 */
		SetScrollPos (hWnd, SB_VERT, iStart);
		break;
	case MSG_PAINT:
		{
			HDC hdc;
			int i;
			RECT rcClient;
			QLOG(TDBG, "初始化滚动条\n");

			GetClientRect (hWnd, &rcClient);
			hdc = BeginPaint (hWnd);
			/* 根据当前滚动位置输出 17 个字符串 */
			for (i = 0; i < 17 - iStart; i++) {
				rcClient.left = 0;
				rcClient.right = (strlen(strLine [i + iStart]) - iStartPos)
				* GetSysCharWidth ();
				rcClient.top = i*20;
				rcClient.bottom = rcClient.top + 20;
				TextOut (hdc, 0, i*20, strLine [i + iStart] + iStartPos);
			}
			EndPaint (hWnd, hdc);






		}
		return 0;

		/* 销毁插入符及主窗口 */
	case MSG_CLOSE:
		QLOG(TDBG, "销毁插入符及主窗口\n");
		DestroyCaret (hWnd);
		DestroyMainWindow (hWnd);
		PostQuitMessage (hWnd);
		return 0;
	}

	return DefaultMainWinProc(hWnd, message, wParam, lParam);
}


static void InitCreateInfo(PMAINWINCREATE pCreateInfo)
{
	/* 在窗口风格中指定具有水平和垂直滚动条 */
	pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_HSCROLL | WS_VSCROLL;
	pCreateInfo->dwExStyle = WS_EX_NONE | WS_EX_IMECOMPOSE;
	pCreateInfo->spCaption = "The scrollable main window" ;
	pCreateInfo->hMenu = 0;
	pCreateInfo->hCursor = GetSystemCursor(0);
	pCreateInfo->hIcon = 0;
	pCreateInfo->MainWindowProc = ScrollWinProc;
	pCreateInfo->lx = 0;
	pCreateInfo->ty = 0;
	pCreateInfo->rx = 400;
	pCreateInfo->by = 280;
	pCreateInfo->iBkColor = COLOR_lightwhite;
	pCreateInfo->dwAddData = 0;
	pCreateInfo->hHosting = HWND_DESKTOP;
}

int MINI_TEST_ScrollWin(void)
{
	MSG Msg;
	MAINWINCREATE CreateInfo;
	HWND hMainWnd;

	InitCreateInfo(&CreateInfo);
	hMainWnd = CreateMainWindow(&CreateInfo);
	if (hMainWnd == HWND_INVALID)
		return 1;



	ShowWindow(hMainWnd, SW_SHOW);

	while (GetMessage(&Msg, hMainWnd) ) {
		DispatchMessage(&Msg);
	}
	MainWindowThreadCleanup(hMainWnd);
	return 0;
}














#if 1

/** define scrollbar data */
#define SB_MAX 20
#define SB_MIN 0
#define SB_PAGE 6

/** define circle data */
#define CC_CENTER_X    400
#define CC_CENTER_Y    100
#define CC_RADIUS_MAX   50
#define CC_RADIUS_MIN   0

/** define box data */
#define BOX_WIDTH   40
#define BOX_HEIGHT  20
#define BOX_Y_MAX   300
#define BOX_Y_MIN   200

/** x position of separator */
#define SEP   300

/** radius of circle */
int _radius;

/** y position of box */
int _box_pos_y;

/** invalidate rect */
RECT _rect_invalid;
#define SCB_ST_CAP "滚动条示例"

void calc_circle_pos (int curPos)
{
    _radius = (CC_RADIUS_MAX - CC_RADIUS_MIN + 1) *
        (curPos - SB_MIN) / (SB_MAX - SB_MIN) + CC_RADIUS_MIN;
}

void calc_box_pos (int curPos)
{
    _box_pos_y = (BOX_Y_MAX - BOX_Y_MIN + 1 - BOX_HEIGHT) *
        (curPos - SB_MIN) / (SB_MAX - SB_MIN) + BOX_Y_MIN;
}

void draw_shape (HWND hwnd, int curPos)
{
    if (curPos < SB_MIN)
        curPos = SB_MIN;
    if (curPos > SB_MAX)
        curPos = SB_MAX;

    calc_circle_pos (curPos);
    calc_box_pos (curPos);
    InvalidateRect (hwnd, &_rect_invalid, TRUE);
}

static int ScrollbarProc(HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
    /** IDC of SCROLLBAR control */
    static int _my_scroll_idc = 100;

    /** scrollbar handle of main window  */
    static HWND hwnd_sb_main;

    /** scrollbar handle of control */
    HWND hwnd_sb_ctrl;

    switch (message)
    {
        case MSG_CREATE:
            {
                _rect_invalid.left   = SEP;
                _rect_invalid.top    = 0;
                _rect_invalid.right  = g_rcScr.right;
                _rect_invalid.bottom = g_rcScr.bottom;

                SCROLLINFO scinfo = {0};
                scinfo.fMask = SIF_ALL;
                scinfo.nMin = SB_MIN;
                scinfo.nMax = SB_MAX;
                scinfo.nPage = SB_PAGE;
                scinfo.nPos = SB_MIN;

                calc_circle_pos (scinfo.nPos);
                calc_box_pos (scinfo.nPos);

                /** classic VSCROLL with SBS_NOTNOTIFYPARENT */

                hwnd_sb_main = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE |
                        SBS_VERT | SBS_LEFTALIGN
                        | SBS_NOTNOTIFYPARENT,
                        0,
                        ++_my_scroll_idc,
                        20, 50, 20, 150, hwnd,
                        "classic", 0,
                        0);

                SendMessage (hwnd_sb_main, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_main, MSG_SETFOCUS, 0, 0);

                /** flat VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE |
                        SBS_VERT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        43, 50, 20, 150, hwnd,
                        "flat", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** fashion VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE |
                        SBS_VERT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        66, 50, 20, 150, hwnd,
                        "fashion", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** tiny VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE |
                        SBS_VERT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        92, 50, 20, 150, hwnd,
                        "tiny", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** classic NOSHAFT VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOSHAFT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        120, 50, 20, 34, hwnd,
                        "classic", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** flat NOSHAFT VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOSHAFT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        140, 50, 20, 34, hwnd,
                        "flat", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** fashion NOSHAFT VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOSHAFT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        160, 50, 20, 34, hwnd,
                        "fashion", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** tiny NOSHAFT VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOSHAFT | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        184, 50, 20, 34, hwnd,
                        "tiny", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** classic NOARROW VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOARROW | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        210, 50, 20, 150, hwnd,
                        "classic", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** flat NOARROW VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOARROW | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        232, 50, 20, 150, hwnd,
                        "flat", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** fashion NOARROW VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOARROW | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        254, 50, 20, 150, hwnd,
                        "fashion", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** tiny NOARROW VSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_VERT | SBS_NOARROW | SBS_LEFTALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        276, 50, 20, 150, hwnd,
                        "tiny", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** classic HSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_HORZ
                        | SBS_TOPALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        20, 220, 150, 20, hwnd,
                        "classic", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** flat HSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_HORZ
                        | SBS_TOPALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        20, 240, 150, 20, hwnd,
                        "flat", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** fashion HSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_HORZ
                        | SBS_TOPALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        20, 260, 150, 20, hwnd,
                        "fashion", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);

                /** tiny HSCROLL */

                hwnd_sb_ctrl = CreateWindowEx2 (CTRL_SCROLLBAR, "",
                        WS_VISIBLE | SBS_HORZ
                        | SBS_TOPALIGN
                       ,
                        0,
                        ++_my_scroll_idc,
                        20, 280, 150, 20, hwnd,
                        "tiny", 0,
                        0);

                SendMessage (hwnd_sb_ctrl, SBM_SETSCROLLINFO, (WPARAM)&scinfo, TRUE);
                SendMessage (hwnd_sb_ctrl, MSG_SETFOCUS, 0, 0);
            }
            break;

        case MSG_COMMAND:
            {
                int code = HIWORD(wParam);
                HWND scroll = (HWND)lParam;
                int pos = 0;

                switch (code)
                {
                    case SB_LINELEFT:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            SendMessage (scroll, SBM_SETPOS, --pos, TRUE);
                        }

                        break;

                    case SB_LINERIGHT:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            SendMessage (scroll, SBM_SETPOS, ++pos, TRUE);
                        }
                        break;

                    case SB_PAGELEFT:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            pos -= SB_PAGE;
                            SendMessage (scroll, SBM_SETPOS, pos, TRUE);
                        }
                        break;

                    case SB_PAGERIGHT:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            pos += SB_PAGE;
                            SendMessage (scroll, SBM_SETPOS, pos, TRUE);
                        }
                        break;

                    case SB_LINEUP:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            SendMessage (scroll, SBM_SETPOS, --pos, TRUE);
                        }

                        break;

                    case SB_LINEDOWN:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            SendMessage (scroll, SBM_SETPOS, ++pos, TRUE);
                        }
                        break;

                    case SB_PAGEUP:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            pos -= SB_PAGE;
                            SendMessage (scroll, SBM_SETPOS, pos, TRUE);
                        }
                        break;

                    case SB_PAGEDOWN:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);

                            pos += SB_PAGE;
                            SendMessage (scroll, SBM_SETPOS, pos, TRUE);
                        }
                        break;

                    case SB_THUMBPOSITION:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);
                        }
                        break;

                    case SB_THUMBTRACK:
                        {
                            pos = SendMessage (scroll, SBM_GETPOS, 0, 0);
                        }
                        break;

                    case SB_TOP:
                        {
                            pos = SB_MIN;
                        }
                        break;

                    case SB_BOTTOM:
                        {
                            pos = SB_MAX;
                        }
                        break;

                    default:
                        break;
                }

                draw_shape (hwnd, pos);
            }
            break;

        case MSG_HSCROLL:
            {
                int pos = 0;
                switch (wParam)
                {
                    case SB_LINELEFT:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            SendMessage (hwnd_sb_main, SBM_SETPOS, --pos, TRUE);
                        }

                        break;

                    case SB_LINERIGHT:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            SendMessage (hwnd_sb_main, SBM_SETPOS, ++pos, TRUE);
                        }
                        break;

                    case SB_PAGELEFT:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            pos -= SB_PAGE;
                            SendMessage (hwnd_sb_main, SBM_SETPOS, pos, TRUE);
                        }
                        break;

                    case SB_PAGERIGHT:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            pos += SB_PAGE;
                            SendMessage (hwnd_sb_main, SBM_SETPOS, pos, TRUE);
                        }
                        break;
                    case SB_THUMBPOSITION:
                        {
                            pos = (int)lParam;
                        }
                        break;

                    case SB_THUMBTRACK:
                        {
                            pos = (int)lParam;
                        }
                        break;

                    case SB_TOP:
                        {
                            pos = SB_MIN;
                        }
                        break;

                    case SB_BOTTOM:
                        {
                            pos = SB_MAX;
                        }
                        break;

                    default:
                        break;
                }
                draw_shape (hwnd, pos);
            }
            break;

        case MSG_VSCROLL:
            {
                int pos = 0;
                switch (wParam)
                {
                    case SB_LINEUP:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            SendMessage (hwnd_sb_main, SBM_SETPOS, --pos, TRUE);

                        }

                        break;

                    case SB_LINEDOWN:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            SendMessage (hwnd_sb_main, SBM_SETPOS, ++pos, TRUE);
                        }
                        break;

                    case SB_PAGEUP:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            pos -= SB_PAGE;
                            SendMessage (hwnd_sb_main, SBM_SETPOS, pos, TRUE);
                        }
                        break;

                    case SB_PAGEDOWN:
                        {
                            pos = SendMessage (hwnd_sb_main, SBM_GETPOS, 0, 0);

                            pos += SB_PAGE;
                            SendMessage (hwnd_sb_main, SBM_SETPOS, pos, TRUE);
                        }
                        break;
                    case SB_THUMBPOSITION:
                        {
                            pos = (int)lParam;
                        }
                        break;

                    case SB_THUMBTRACK:
                        {
                            pos = (int)lParam;
                        }
                        break;

                    case SB_TOP:
                        {
                            pos = SB_MIN;
                        }
                        break;

                    case SB_BOTTOM:
                        {
                            pos = SB_MAX;
                        }
                        break;
                    default:
                        break;
                }
                draw_shape (hwnd, pos);
            }
            break;

        case MSG_PAINT:
            {
                HDC hdc = BeginPaint(hwnd);

                /** separator */
                MoveTo (hdc, SEP, 0);
                LineTo (hdc, SEP, g_rcScr.bottom);

                /** circle */
                Circle (hdc, CC_CENTER_X, CC_CENTER_Y, _radius);

                /** top and bottom line of box */
                MoveTo (hdc, SEP + 20, BOX_Y_MIN);
                LineTo (hdc, SEP + 20 + BOX_WIDTH + 40, BOX_Y_MIN);

                MoveTo (hdc, SEP + 20, BOX_Y_MAX);
                LineTo (hdc, SEP + 20 + BOX_WIDTH + 40, BOX_Y_MAX);

                /** box */
                SetBrushColor (hdc, PIXEL_black);
                FillBox (hdc, SEP + 40, _box_pos_y, BOX_WIDTH, BOX_HEIGHT);

                EndPaint (hwnd, hdc);
            }
            break;

        case MSG_CLOSE:
            {
                DestroyMainWindow (hwnd);
                PostQuitMessage (hwnd);
                return 0;
            }
    }

    return DefaultMainWinProc(hwnd, message, wParam, lParam);
}



int MINI_TEST_Scrollbar(void)
{
    MSG Msg;
    HWND hMainWnd;
    MAINWINCREATE CreateInfo;


    CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
    CreateInfo.dwExStyle = WS_EX_NONE;
    CreateInfo.spCaption = SCB_ST_CAP;
    CreateInfo.hMenu = 0;
    CreateInfo.hCursor = GetSystemCursor(0);
    CreateInfo.hIcon = 0;
    CreateInfo.MainWindowProc = ScrollbarProc;
    CreateInfo.lx = 0;
    CreateInfo.ty = 0;
    CreateInfo.rx = g_rcScr.right;
    CreateInfo.by = g_rcScr.bottom;
    CreateInfo.iBkColor = COLOR_lightwhite;
    CreateInfo.dwAddData = 0;
    CreateInfo.hHosting = HWND_DESKTOP;

    hMainWnd = CreateMainWindowEx (&CreateInfo, "flat", 0, 0, 0);

    if (hMainWnd == HWND_INVALID)
    {
        return -1;
    }

    ShowWindow(hMainWnd, SW_SHOWNORMAL);

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup (hMainWnd);

    return 0;
}



#endif










#define IDC_SCROLLWND 100
#define ID_ZOOMIN 200
#define ID_ZOOMOUT 300
static HWND hScrollWnd;
static BITMAP bmp_bkgnd;
static float current_scale = 1;
static int pic_container_proc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
		case MSG_PAINT:
		{
			HDC hdc = BeginPaint (hWnd);
			FillBoxWithBitmap (hdc, 0, 0, current_scale * bmp_bkgnd.bmWidth,
			current_scale * bmp_bkgnd.bmHeight, &bmp_bkgnd);
			EndPaint (hWnd, hdc);
			return 0;
		}
	}
	return DefaultContainerProc (hWnd, message, wParam, lParam);
}
static int ImageViewerProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message){
	case MSG_INITDIALOG:
	{
		QLOG(TDBG, "图片显示初始化\n");
		hScrollWnd = GetDlgItem (hDlg, IDC_SCROLLWND);
		SendMessage (hScrollWnd, SVM_SETCONTAINERPROC, 0, (LPARAM)pic_container_proc);
		SendMessage (hScrollWnd, SVM_SETCONTRANGE, bmp_bkgnd.bmWidth, bmp_bkgnd.bmHeight);
		break;
	}
	case MSG_COMMAND:
	{
		QLOG(TDBG, "图片缩放命令\n");
		int id = LOWORD(wParam);
		if (id == ID_ZOOMIN || id == ID_ZOOMOUT) {
				current_scale += (id == ID_ZOOMIN) ? 0.2 : -0.2;
				if (current_scale < 0.1)
				current_scale = 0.1;
				SendMessage (hScrollWnd, SVM_SETCONTRANGE,
					current_scale * bmp_bkgnd.bmWidth,
					current_scale * bmp_bkgnd.bmHeight);
				InvalidateRect (hScrollWnd, NULL, TRUE);
			}
			break;
		}
	case MSG_CLOSE:
		EndDialog (hDlg, 0);
		return 0;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}


static CTRLDATA CtrlViewer[] =
{
	{
		"ScrollWnd",
		WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,
		10, 10, 300, 200,
		IDC_SCROLLWND,
		"image viewer",
		0
	},
	{
		CTRL_BUTTON,
		WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
		20, 220, 60, 25,
		ID_ZOOMIN,
		"放大",
		0
	},
	{
		CTRL_BUTTON,
		WS_TABSTOP | WS_VISIBLE | BS_PUSHBUTTON,
		220, 220, 60, 25,
		ID_ZOOMOUT,
		"缩小",
		0
	}
};

static DLGTEMPLATE DlgViewer =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	0, 0, 350, 280,
	"图片显示",
	0, 0,
	TABLESIZE(CtrlViewer), CtrlViewer,
	0
};

int MINI_TEST_ImageViewer(void)
{

	if(LoadBitmap(HDC_SCREEN, &bmp_bkgnd, "share/res/png/menu/单面画-黄.png"))
		return 1;
	DialogBoxIndirectParam (&DlgViewer, HWND_DESKTOP, ImageViewerProc, 0L);
	UnloadBitmap (&bmp_bkgnd);
	return 0;
}













#define IDC_SCROLLVIEW 100
#define IDC_BT 200
#define IDC_BT2 300
#define IDC_BT3 400
#define IDC_BT4 500
static HWND hScrollView;
static const char *people[] =
{
	"朋友",
	"好朋友",
	"Eric Liang",
	"Hellen Zhang",
	"Tomas Zhao",
	"William Sun",
	"Alex Zhang"
};

static void myDrawItem (HWND hWnd, HSVITEM hsvi, HDC hdc, RECT *rcDraw)
{
	const char *name = (const char*)scrollview_get_item_adddata (hsvi);
	SetBkMode (hdc, BM_TRANSPARENT);
	SetTextColor (hdc, PIXEL_black);
	if (scrollview_is_item_hilight(hWnd, hsvi)) {
		SetBrushColor (hdc, PIXEL_blue);
		FillBox (hdc, rcDraw->left+1, rcDraw->top+1, RECTWP(rcDraw)-2, RECTHP(rcDraw)-1);
		SetBkColor (hdc, PIXEL_blue);
		SetTextColor (hdc, PIXEL_lightwhite);
	}
	Rectangle (hdc, rcDraw->left, rcDraw->top, rcDraw->right - 1, rcDraw->bottom);
	TextOut (hdc, rcDraw->left + 3, rcDraw->top + 2, name);
}

static int myCmpItem (HSVITEM hsvi1, HSVITEM hsvi2)
{
	const char *name1 = (const char*)scrollview_get_item_adddata (hsvi1);
	const char *name2 = (const char*)scrollview_get_item_adddata (hsvi2);
	return strcmp (name1, name2);
}

static int BookProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{	QLOG(TDBG, "有信息过来\n");
		case MSG_INITDIALOG:
		{
			SVITEMINFO svii;
			static int i = 0;
			hScrollView = GetDlgItem (hDlg, IDC_SCROLLVIEW);
			SetWindowBkColor (hScrollView, PIXEL_lightwhite);
			SendMessage (hScrollView, SVM_SETITEMCMP, 0, (LPARAM)myCmpItem);
			SendMessage (hScrollView, SVM_SETITEMDRAW, 0, (LPARAM)myDrawItem);
			for (i = 0; i < TABLESIZE(people); i++) {
			svii.nItemHeight = 32;
			svii.addData = (DWORD)people[i];
			svii.nItem = i;
			SendMessage (hScrollView, SVM_ADDITEM, 0, (LPARAM)&svii);
		}
		break;
		}
		case MSG_COMMAND:
		{
			int id = LOWORD (wParam);
			int code = HIWORD (wParam);
			switch (id) {
				case IDC_SCROLLVIEW:
				if (code == SVN_CLICKED) {
					int sel;
					sel = SendMessage (hScrollView, SVM_GETCURSEL, 0, 0);
					InvalidateRect (hScrollView, NULL, TRUE);
					}
					break;
				}
			break;
		}
		case MSG_CLOSE:
		{
			EndDialog (hDlg, 0);
			return 0;
		}
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}

static CTRLDATA CtrlBook[] =
{
	{
	"ScrollView",
	WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
	SVS_AUTOSORT,
	10, 10, 320, 150,
	IDC_SCROLLVIEW,
	"",
	0
	},
};

static DLGTEMPLATE DlgBook =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	0, 0, 350, 200,
	"My Friends",
	0, 0,
	TABLESIZE(CtrlBook), NULL,
	0
};

int MINI_TEST_Book(void)
{
	DlgBook.controls = CtrlBook;
	DialogBoxIndirectParam (&DlgBook, HWND_DESKTOP, BookProc, 0L);

	return 0;
}









#define CAPTION "载入与显示图片"


static int SimplekeyWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case MSG_KEYDOWN:
        printf ("MGS_KEYDOWN: key %d\n", LOWORD(wParam));
        break;

    case MSG_KEYUP:
        printf ("MGS_KEYUP: key %d\n", LOWORD(wParam));
        break;

    case MSG_CHAR:
        printf ("MGS_CHAR: char %d\n", wParam);
        break;

    case MSG_CLOSE:
        DestroyAllControls (hWnd);
        DestroyMainWindow (hWnd);
        PostQuitMessage (hWnd);
        return 0;
    }

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}

int MINI_TEST_Key(void)
{
    MSG Msg;
    HWND hMainWnd;
    MAINWINCREATE CreateInfo;



    CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
    CreateInfo.dwExStyle = WS_EX_NONE;
    CreateInfo.spCaption = CAPTION;
    CreateInfo.hMenu = 0;
    CreateInfo.hCursor = GetSystemCursor(0);
    CreateInfo.hIcon = 0;
    CreateInfo.MainWindowProc = SimplekeyWinProc;
    CreateInfo.lx = 0;
    CreateInfo.ty = 0;
    CreateInfo.rx = 320;
    CreateInfo.by = 240;
    CreateInfo.iBkColor = COLOR_lightwhite;
    CreateInfo.dwAddData = 0;
    CreateInfo.hHosting = HWND_DESKTOP;

    hMainWnd = CreateMainWindow (&CreateInfo);

    if (hMainWnd == HWND_INVALID)
        return -1;

    ShowWindow(hMainWnd, SW_SHOWNORMAL);

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup (hMainWnd);

    return 0;
}












#define IDC_BASE 20000
#ifndef IDC_STATIC
#define IDC_STATIC 21000
#endif




static DLGTEMPLATE s_DlgBox_DlgPing =
{
    WS_BORDER | WS_CAPTION,
    WS_EX_NONE,
    200, 225, 400, 180,
    "Ping",
    0, 0,
    4,
    NULL,
    0
};

static CTRLDATA s_DlgCtrl_DlgPing[] =
{
    {
        "button",
        WS_VISIBLE | WS_TABSTOP ,
        47, 91, 100, 28,
        IDOK,
        "确定",
        0
    },
    {
        "button",
        WS_VISIBLE | WS_TABSTOP ,
        217, 91, 100, 28,
        IDCANCEL,
        "取消",
        0
    },
    {
        "sledit",
        WS_VISIBLE | WS_TABSTOP | WS_BORDER,
        127, 40, 199, 30,
        IDC_EDT_ADDR,
        "",
        0
    },
    {
        "static",
        WS_VISIBLE | WS_TABSTOP ,
        42, 42, 70, 34,
        IDC_STATIC,
        "IP地址",
        0
    },
};



void notify_ime_status(BOOL opened)
{
    g_ime_opened = opened;
}

static int DialogBox_DlgPing_Proc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{

    switch (message)
    {
        case MSG_INITDIALOG:
            g_hIMEWnd  = hDlg;
			QLOG(TDBG, "初始化键盘输入\n");
			PLOGFONT gb2312_font = CreateLogFontByName("ttf-simhei-rrncnn-0-0-UTF-8");
			//PLOGFONT gb2312_font = CreateLogFontByName("ttf-simhei-rrncnn-0-0-GB2312");
			//PLOGFONT gb2312_font = CreateLogFont("ttf", "simhei", "UTF-8",FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN,FONT_FLIP_NIL, FONT_OTHER_NIL,
			//				FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,48,0);
			if(gb2312_font == NULL) {
				QLOG(TDBG, "字体为空\n");
			}
			SetWindowFont(hDlg, gb2312_font);

            SetNotificationCallback(GetDlgItem(hDlg, IDC_EDT_ADDR), edit_notif_proc);
            sk_ime_hwnd = mgiCreateSoftKeypad(notify_ime_status);
            SetFocusChild(GetDlgItem(hDlg, IDC_EDT_ADDR));
            SetIMEStatus(IME_STATUS_AUTOTRACK, TRUE);
            SetIMEStatus(IME_STATUS_ENCODING, IME_ENCODING_UTF8);
            SetIMEStatus(IME_STATUS_ENABLED, TRUE);
            return 1;

		case MSG_COMMAND:
			switch (wParam) {
				case IDOK:
				{

					char buff [40];
					/* 从输入框中获得数据，并保存在传入的指针中。
					*/
					//double* length = (double*)GetWindowAdditionalData(hDlg);
					GetWindowText (GetDlgItem (hDlg, IDC_EDT_ADDR), buff, 32);
					QLOG(TDBG, "接收到数据[%s]\n", buff);
					//*length = atof (buff);
				}
			}
			break;
        case MSG_CLOSE:
            EndDialog(hDlg, IDCANCEL);
            break;
    }

    return DefaultDialogProc(hDlg, message, wParam, lParam);
}

int MINI_TEST_SoftKey(void)
{
    s_DlgBox_DlgPing.controls = s_DlgCtrl_DlgPing;

    SetDefaultWindowElementRenderer("flat");

    DialogBoxIndirectParam(&s_DlgBox_DlgPing, HWND_DESKTOP, DialogBox_DlgPing_Proc, 0);
    return 0;
}







int NoteBookWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    RECT client;

    switch (message) {
    case MSG_CREATE:
        GetClientRect(hWnd, &client);
        CreateWindow("textedit",
                 "",  WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL,
                100, 0, 0, client.right,client.bottom , hWnd, 0);
        break;

    case MSG_SHOWWINDOW:
        SetFocus (GetDlgItem (hWnd, 100));
        return 0;

    case MSG_CLOSE:
        DestroyAllControls (hWnd);
        DestroyMainWindow (hWnd);
        PostQuitMessage (hWnd);
        return 0;
    }

    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}

static void InitNoteBookInfo (PMAINWINCREATE pCreateInfo, HWND host)
{
    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_SYSMENU;
    pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE;
    pCreateInfo->spCaption = "mGi test program";
    pCreateInfo->hMenu = 0;
    pCreateInfo->hCursor = GetSystemCursor(0);
    pCreateInfo->hIcon = 0;
    pCreateInfo->MainWindowProc = NoteBookWinProc;
    pCreateInfo->lx = 20;
    pCreateInfo->ty = 200;
    pCreateInfo->rx = 400;
    pCreateInfo->by = 500;
    pCreateInfo->iBkColor = COLOR_lightgray;
    pCreateInfo->dwAddData = 0;
    pCreateInfo->hHosting = host;
}

void* NoteBook (void* data)
{
    MSG Msg;
    MAINWINCREATE CreateInfo;
    HWND hMainWnd;
    //char currentpath[PATH_MAX + 1];
   //static int x = 0, y = 0;

#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
    GHANDLE ime_handle;
    HWND hw_ime_hwnd;
    MGI_HANDWRITE_INFO hw_info;
	memset (&hw_info, 0, sizeof (MGI_HANDWRITE_INFO));

	hw_info.x = 30;
	hw_info.y = 40;
	hw_info.x = 40;
    hw_info.two_wins = TRUE;

    ime_handle = mgiCreateIMEContainer (2, FALSE);
    hw_ime_hwnd = mgiCreateHandWriteIME (&hw_info, NULL);

    mgiAddIMEWindow (ime_handle, hw_ime_hwnd, "handwrite");
    mgiSetActiveIMEWindow (ime_handle, "handwrite");
#endif

    InitNoteBookInfo (&CreateInfo, HWND_DESKTOP);
    hMainWnd = CreateMainWindow(&CreateInfo);

    ShowWindow(hMainWnd, SW_SHOWNORMAL);
    if (hMainWnd == HWND_INVALID) {

#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
        mgiDestroyIMEContainer (ime_handle);
#endif
        return NULL;
    }

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup(hMainWnd);

#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
    mgiDestroyIMEContainer (ime_handle);
#endif
    return NULL;
}

int MINI_TEST_SoftKeyHandWrite(void)
{

#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)
#if (MINIGUI_MAJOR_VERSION > 1)
    JoinLayer(NAME_DEF_LAYER , "notebook" , 0 , 0);
#else
    int i;
    const char* layer = NULL;
    RECT max_rect = {0, 0, 0, 0};

    for (i = 1; i < args; i++) {
        if (strcmp (arg[i], "-layer") == 0) {
            layer = arg[i + 1];
            break;
        }
    }
    GetLayerInfo (layer, &max_rect, NULL, NULL, NULL);
    if (JoinLayer (layer, arg[0],
                max_rect.left, max_rect.top,
                max_rect.left + 800,
                max_rect.top + 600) == INV_LAYER_HANDLE) {
        printf ("JoinLayer: invalid layer handle.\n");
        exit (1);
    }
#endif
#endif

    NoteBook(NULL);
    return 0;
}







int SwitchNoteBookWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    RECT client;


    switch (message) {
    case MSG_CREATE:
		QLOG(TDBG, "接受创建消息\n");
        GetClientRect(hWnd, &client);
        CreateWindow("textedit",
                 "",  WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL,
                100, 0, 0, client.right,client.bottom , hWnd, 0);
        break;

    case MSG_SHOWWINDOW:
        SetFocus (GetDlgItem (hWnd, 100));
        return 0;

    case MSG_CLOSE:
        DestroyAllControls (hWnd);
        DestroyMainWindow (hWnd);
        PostQuitMessage (hWnd);
        return 0;
    }

    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}

static void SwitchInitNoteBookInfo(PMAINWINCREATE pCreateInfo, HWND host)
{
    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER |
                        WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_SYSMENU;
    pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE;
    pCreateInfo->spCaption = "mGi test program";
    pCreateInfo->hMenu = 0;
    pCreateInfo->hCursor = GetSystemCursor(0);
    pCreateInfo->hIcon = 0;
    pCreateInfo->MainWindowProc = SwitchNoteBookWinProc;
    pCreateInfo->lx = 0;
    pCreateInfo->ty = 0;
    pCreateInfo->rx = 400;
    pCreateInfo->by = 300;
    pCreateInfo->iBkColor = COLOR_lightgray;
    pCreateInfo->dwAddData = 0;
    pCreateInfo->hHosting = host;
}

#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
static GHANDLE ime_handle;

static void SwitchMyImeProc(HWND hwnd, int id, int nc, DWORD add_data)
{QLOG(TDBG, "消息\n");
    static int show_sk = 1, show_hw = 1;
    switch (nc) {
        case MGIN_SKIME:
            if (show_sk)
            {
                mgiSetActiveIMEWindow (ime_handle, "softkeyboard");
                show_sk = 0;
                show_hw = 1;
            } else {
                mgiSetActiveIMEWindow (ime_handle, "");
                show_sk = 1;
            }
            break;
        case MGIN_HWIME:
            if (show_hw)
            {
                mgiSetActiveIMEWindow (ime_handle, "handwrite");
                show_hw = 0;
                show_sk = 1;
            } else {
                mgiSetActiveIMEWindow (ime_handle, "");
                show_hw = 1;
            }
            break;
        default:
            break;
    };
}
#endif

void* SwitchNoteBook(void* data)
{
    MSG Msg;
    MAINWINCREATE CreateInfo;
    HWND hMainWnd;

#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
    HWND sk_ime_hwnd, hw_ime_hwnd;
    MGI_SOFTKEYBOARD_INFO sk_info;
    MGI_HANDWRITE_INFO hw_info;
    int ret;

    memset (&sk_info, 0, sizeof(MGI_SOFTKEYBOARD_INFO));
    memset (&hw_info, 0, sizeof(MGI_HANDWRITE_INFO));
	QLOG(TDBG, "创建键盘\n");
    //hw_info.x = g_rcScr.right - 300;
    //hw_info.y = g_rcScr.bottom - 160;
	hw_info.x = 40;
    hw_info.y = 40;
    hw_info.w = 280;
    hw_info.h = 150;
    hw_info.two_wins = TRUE;

    ime_handle = mgiCreateIMEContainer (2, TRUE);
    sk_ime_hwnd = mgiCreateSoftKeyboardIME (&sk_info, NULL);
    hw_ime_hwnd = mgiCreateHandWriteIME (&hw_info, NULL);

    ret = mgiAddIMEWindow (ime_handle, sk_ime_hwnd, "softkeyboard");
    ret = mgiAddIMEWindow (ime_handle, hw_ime_hwnd, "handwrite");

    mgiAddSKBTranslateOps(sk_ime_hwnd, &quanpin_trans_ops);
    mgiSetNotificationCallback (ime_handle, SwitchMyImeProc);
#endif

    SwitchInitNoteBookInfo(&CreateInfo, HWND_DESKTOP);
    hMainWnd = CreateMainWindow(&CreateInfo);

    ShowWindow(hMainWnd, SW_SHOWNORMAL);
    if (hMainWnd == HWND_INVALID)
    {
#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
        mgiDestroyIMEContainer (ime_handle);
#endif
        return NULL;
    }

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup(hMainWnd);

#if !defined(_LITE_VERSION) || defined(_STAND_ALONE)
    mgiDestroyIMEContainer (ime_handle);
#endif

    return NULL;
}

int MINI_TEST_Switch(void)
{

#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)
#if (MINIGUI_MAJOR_VERSION > 1)
    JoinLayer(NAME_DEF_LAYER , "notebook" , 0 , 0);
#else
    int i;
    const char* layer = NULL;
    RECT max_rect = {0, 0, 0, 0};

    for (i = 1; i < args; i++) {
        if (strcmp (arg[i], "-layer") == 0) {
            layer = arg[i + 1];
            break;
        }
    }
    GetLayerInfo (layer, &max_rect, NULL, NULL, NULL);
    if (JoinLayer (layer, arg[0],
                max_rect.left, max_rect.top,
                max_rect.left + 800,
                max_rect.top + 600) == INV_LAYER_HANDLE) {
        printf ("JoinLayer: invalid layer handle.\n");
        exit (1);
    }
#endif
#endif

    SwitchNoteBook(NULL);
    return 0;
}










int KtNoteBookWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    RECT client;

    switch (message) {
    case MSG_CREATE:
        GetClientRect(hWnd, &client);
        CreateWindow("textedit",
                 "",  WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL,
                100, 0, 0, client.right,client.bottom , hWnd, 0);
        break;

    case MSG_SHOWWINDOW:
        printf( "show window\n" );
        SetFocus (GetDlgItem (hWnd, 100));
        return 0;

    case MSG_CLOSE:
        DestroyAllControls (hWnd);
        DestroyMainWindow (hWnd);
        PostQuitMessage (hWnd);
        return 0;
    }

    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}

static void KtInitNoteBookInfo(PMAINWINCREATE pCreateInfo, HWND host)
{
    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER |
                        WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_SYSMENU;
    pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE;
    pCreateInfo->spCaption = "mGi test program";
    pCreateInfo->hMenu = 0;
    pCreateInfo->hCursor = GetSystemCursor(0);
    pCreateInfo->hIcon = 0;
    pCreateInfo->MainWindowProc = KtNoteBookWinProc;
    pCreateInfo->lx = 0;
    pCreateInfo->ty = 0;
    pCreateInfo->rx = 400;
    pCreateInfo->by = 300;
    pCreateInfo->iBkColor = COLOR_lightgray;
    pCreateInfo->dwAddData = 0;
    pCreateInfo->hHosting = host;
}
void* KtNoteBook(void* data)
{
    MSG Msg;
    MAINWINCREATE CreateInfo;
    HWND hMainWnd;
   // char currentpath[PATH_MAX + 1];
  //  static int x = 0, y = 0;


    KtInitNoteBookInfo(&CreateInfo, HWND_DESKTOP);
    hMainWnd = CreateMainWindow(&CreateInfo);

    ShowWindow(hMainWnd, SW_SHOWNORMAL);
    if (hMainWnd == HWND_INVALID)
    {
        return NULL;
    }

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup(hMainWnd);


    return NULL;
}

int MINI_TEST_Kt(void)
{

#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)
#if (MINIGUI_MAJOR_VERSION > 1)
    JoinLayer(NAME_DEF_LAYER , "notebook" , 0 , 0);
#else
    int i;
    const char* layer = NULL;
    RECT max_rect = {0, 0, 0, 0};

    for (i = 1; i < args; i++) {
        if (strcmp (arg[i], "-layer") == 0) {
            layer = arg[i + 1];
            break;
        }
    }
    GetLayerInfo (layer, &max_rect, NULL, NULL, NULL);
    if (JoinLayer (layer, arg[0],
                max_rect.left, max_rect.top,
                max_rect.left + 800,
                max_rect.top + 600) == INV_LAYER_HANDLE) {
        printf ("JoinLayer: invalid layer handle.\n");
        exit (1);
    }
#endif
#endif

    KtNoteBook(NULL);
    return 0;
}










#define IDC_CHARS1       100
#define IDC_CHARS2       101
#define IDC_CHAR1         102
#define IDC_CHAR2         103
#define IDC_CHAR3         104

#define IDC_GB2312          111
#define IDC_UTF8            112
#define IDC_AUTOTRACK       114
#define IDC_NOTRACK         115

#define IDC_LATIN       117
#define IDC_ZHCN        118

#define EDIT_NUM        5
static unsigned int EDITS_ID[EDIT_NUM] ={IDC_CHARS1, IDC_CHARS2,IDC_CHAR1, IDC_CHAR2, IDC_CHAR3};

#define dbg() printf("%s %d\n", __FUNCTION__, __LINE__);
static PLOGFONT big5_font;
static PLOGFONT utf8_font;
static PLOGFONT gb2312_font;



#ifndef _MGRM_PROCESSES
static HWND sk_ime_hwnd;
#endif
static HWND g_current_hwnd;
//static BOOL g_ime_opened = FALSE;
static CTRLDATA CtrlInputChar [] =
{
    {
        CTRL_STATIC,
        WS_VISIBLE,
        10, 10, 380, 25,
        IDC_STATIC,
        "EDITABLE",
        0
    },
    {
        CTRL_STATIC,
        WS_VISIBLE,
        10, 50, 380, 25,
        IDC_STATIC,
        "PASSWORD",
        0
    },
    {
        CTRL_STATIC,
        WS_VISIBLE,
        10, 90, 380, 25,
        IDC_STATIC,
        "READ ONLY",
        0
    },


    {
        CTRL_SLEDIT,
        WS_VISIBLE | WS_TABSTOP | WS_BORDER,
        120, 10, 180, 25,
        IDC_CHAR1,
        NULL,
        0
    },
    {
        CTRL_SLEDIT,
        WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_PASSWORD,
        120, 50, 180, 25,
        IDC_CHAR2,
        NULL,
        0
    },
    {
        CTRL_SLEDIT,
        WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_READONLY,
        120, 90, 180, 25,
        IDC_CHAR3,
        NULL,
        0
    },

    {
        CTRL_MLEDIT,
        WS_VISIBLE | WS_VSCROLL
            | ES_BASELINE | ES_AUTOWRAP | ES_NOHIDESEL | ES_NOHIDESEL,//| WS_DISABLED,
        0, 150, 155, 200,
        IDC_CHARS1,
        NULL,
        0
    },
    {
        CTRL_MLEDIT,
        WS_VISIBLE | WS_VSCROLL
            | ES_BASELINE | ES_AUTOWRAP | ES_NOHIDESEL | ES_NOHIDESEL,//| WS_DISABLED,
        165, 150, 155, 200,
        IDC_CHARS2,
        NULL,
        0
    },

    {
        CTRL_BUTTON,
        WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CHECKED | WS_TABSTOP | WS_GROUP,
        20, 380, 80, 34,
        IDC_GB2312,
        "GB2312",
        0
    },
    {
        CTRL_BUTTON,
        WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
        20, 420, 80, 34,
        IDC_UTF8,
        "UTF8",
        0
    },

    {
        CTRL_BUTTON,
        WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CHECKED | WS_TABSTOP | WS_GROUP,
        120, 380, 80, 34,
        IDC_LATIN,
        "ENG",
        0
    },
    {
        CTRL_BUTTON,
        WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
        120, 420, 80, 34,
        IDC_ZHCN,
        "ZHCN",
        0
    },

    {
        CTRL_BUTTON,
        WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CHECKED | WS_TABSTOP | WS_GROUP,
        200, 380, 90, 34,
        IDC_AUTOTRACK,
        "AUTOTRACK",
        0
    },

    {
        CTRL_BUTTON,
        WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
        200, 420, 90, 34,
        IDC_NOTRACK,
        "NOTRACK",
        0
    },
};

static DLGTEMPLATE DlgBoxInputChar =
{
    WS_CAPTION,
    WS_EX_NONE,
    0, 0, 320, 500,
    "",
    0, 0,
    TABLESIZE(CtrlInputChar), NULL,
    0
};


static void btn_notif_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
    int i = 0;

    if (id == IDC_GB2312 && nc == BN_CLICKED) {
		QLOG(TDBG, "IDC_GB2312 \n");
        SetIMEStatus(IME_STATUS_ENCODING, IME_ENCODING_LOCAL);
        printf("hwnd = %d\n", hwnd);
        for(i = 0; i < EDIT_NUM; ++i) {
            SetWindowFont(GetDlgItem(GetParent(hwnd), EDITS_ID[i]),gb2312_font);
        }
    }  else if (id == IDC_UTF8 && nc == BN_CLICKED) {
        SetIMEStatus(IME_STATUS_ENCODING, IME_ENCODING_UTF8);
        for(i = 0; i < EDIT_NUM; ++i) {
            SetWindowFont(GetDlgItem(GetParent(hwnd), EDITS_ID[i]), utf8_font);
        }
    } else if (id == IDC_AUTOTRACK && nc == BN_CLICKED) {
        SetIMEStatus(IME_STATUS_AUTOTRACK, TRUE);
    } else if (id == IDC_NOTRACK && nc == BN_CLICKED) {
        SetIMEStatus(IME_STATUS_AUTOTRACK, FALSE);
    } else if (id == IDC_ZHCN && nc == BN_CLICKED) {
        SetIMEStatus(IME_STATUS_LANGUAGE, IME_LANGUAGE_ZHCN);
    } else if (id == IDC_LATIN && nc == BN_CLICKED) {
        SetIMEStatus(IME_STATUS_LANGUAGE, IME_LANGUAGE_LATIN);
    }
}
/*
static void edit_notif_proc(HWND hDlg, int id, int nc, DWORD add_data)
{
    IME_TARGET_INFO ime_t_info;
    //edit控件的消息处理函数中打印caret的位置
    GetIMETargetInfo(&ime_t_info);
    printf("ime_t_info.ptCaret: (%d, %d)\n", ime_t_info.ptCaret.x, ime_t_info.ptCaret.y);
}
*/
static int InputCharDialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
    g_current_hwnd = hDlg;
    switch (message) {
    case MSG_INITDIALOG:
        SetNotificationCallback (GetDlgItem (hDlg, IDC_GB2312), btn_notif_proc);
        SetNotificationCallback (GetDlgItem (hDlg, IDC_UTF8), btn_notif_proc);
        SetNotificationCallback (GetDlgItem (hDlg, IDC_AUTOTRACK), btn_notif_proc);
        SetNotificationCallback (GetDlgItem (hDlg, IDC_NOTRACK), btn_notif_proc);
        SetNotificationCallback (GetDlgItem (hDlg, IDC_LATIN), btn_notif_proc);
        SetNotificationCallback (GetDlgItem (hDlg, IDC_ZHCN), btn_notif_proc);

        SetNotificationCallback (GetDlgItem (hDlg, IDC_CHAR1), edit_notif_proc);
        SetNotificationCallback (GetDlgItem (hDlg, IDC_CHARS1), edit_notif_proc);

        //utf8_font = CreateLogFontByName("upf-fmsong-rrncnn-12-12-UTF-8");
		utf8_font = CreateLogFontByName("ttf-simhei-rrncnn-*-12-UTF-8");
        gb2312_font = CreateLogFontByName("upf-fmsong-rrncnn-12-12-GB2312");
        big5_font = CreateLogFontByName("upf-fmsong-rrncnn-12-12-BIG5");
        if(NULL == utf8_font->mbc_devfont) {
            printf("utf8_font CreateLogFontByName Failed!\n");
        }

        if(NULL == gb2312_font->mbc_devfont) {
            printf("gb2312_font CreateLogFontByName Failed!\n");
        }

        if (NULL == big5_font->mbc_devfont) {
            printf("big5_font CreateLogFontByName Failed!\n");
        }

        int i = 0;
        for(i = 0; i < EDIT_NUM; ++i) {
            SetWindowFont(GetDlgItem(hDlg, EDITS_ID[i]),utf8_font);
        }

#ifndef _MGRM_PROCESSES
        sk_ime_hwnd = mgiCreateSoftKeypad(notify_ime_status);
#endif
        SetFocusChild(GetDlgItem(hDlg, IDC_CHAR1));
        SetIMEStatus(IME_STATUS_AUTOTRACK, TRUE);
		SetIMEStatus(IME_STATUS_LANGUAGE, IME_LANGUAGE_ZHCN);
        SetIMEStatus(IME_STATUS_ENCODING,IME_ENCODING_UTF8);
        SetIMEStatus(IME_STATUS_ENABLED, TRUE);
        printf("MSG_INITDIALOG: GetIMEStatus(IME_STATUS_ENABLED): %d\n",  GetIMEStatus(IME_STATUS_ENABLED));
        return 1;
    case MSG_CLOSE:
        DestroyLogFont(utf8_font);
        DestroyLogFont(gb2312_font);
        DestroyLogFont(big5_font);
        PostMessage (GetParent(hDlg), MSG_CLOSE, 0, 0);
        EndDialog (hDlg, IDCANCEL);
        break;
    }
    return DefaultDialogProc (hDlg, message, wParam, lParam);
}
/*
void notify_ime_status(BOOL opened)
{
    g_ime_opened = opened;
}
*/
int MINIGUI_TEST_SoftKey(void)
{


#ifndef _MGRM_THREADS
    if (!InitVectorialFonts ()) {
        printf ("InitVectorialFonts: error.\n");
        return 1;
    }
#endif

    DlgBoxInputChar.controls = CtrlInputChar;
    DialogBoxIndirectParam (&DlgBoxInputChar, HWND_DESKTOP, InputCharDialogBoxProc, 0L);

#ifndef _MGRM_THREADS
    TermVectorialFonts ();
#endif
    return 0;
}





static int PainterWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;

	/* 设定静态变量保存运行状态以及鼠标按下的位置 */
    static BOOL bdraw = FALSE;
    static int pre_x, pre_y;

    switch (message) {
    case MSG_LBUTTONDOWN:
		/* 进入绘制状态；捕获鼠标并记录鼠标按下的位置 */
        SetCapture(hWnd);
        bdraw = TRUE;
        pre_x = LOWORD (lParam);
        pre_y = HIWORD (lParam);
        break;
		QLOG(TDBG, "捕获鼠标 pre_x[%d] pre_y[%d]\n", pre_x, pre_y);
    case MSG_MOUSEMOVE:
    {
        int x = LOWORD (lParam);
        int y = HIWORD (lParam);
		QLOG(TDBG, "鼠标移动 x[%d] y[%d]\n", x, y);

        if (bdraw) {
			/* 如果是绘制状态，则表明鼠标被捕获，
			 * 因此需要将鼠标坐标从屏幕坐标转换为客户区坐标
			 */
            ScreenToClient(hWnd, &x, &y);
			/* 获取客户区设备上下文并开始绘制 */
            hdc = GetClientDC(hWnd);
            SetPenColor(hdc, PIXEL_red);
			/* 从先前的位置画直线到当前鼠标位置 */
            MoveTo(hdc, pre_x, pre_y);
            LineTo(hdc, x, y);
            ReleaseDC(hdc);
			/* 已当前鼠标位置更新先前的位置 */
            pre_x = x;
            pre_y = y;
        }
        break;
    }

    case MSG_LBUTTONUP:
    {
        int x = LOWORD (lParam);
        int y = HIWORD (lParam);

        if (bdraw) {
            ScreenToClient(hWnd, &x, &y);
            hdc = GetClientDC(hWnd);
            SetPixel (hdc, x, y, PIXEL_red);
            ReleaseDC(hdc);
			/* 退出绘图状态，并释放鼠标 */
            bdraw = FALSE;
            ReleaseCapture();
        }
        break;
    }

    case MSG_RBUTTONDOWN:
		/* 按鼠标右键将清除窗口 */
        InvalidateRect(hWnd, NULL, TRUE);
        break;

    case MSG_CLOSE:
        DestroyAllControls (hWnd);
        DestroyMainWindow (hWnd);
        PostQuitMessage (hWnd);
        return 0;
    }

    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}

int MINI_TEST_Painter(void)
{
    MSG Msg;
    HWND hMainWnd;
    MAINWINCREATE CreateInfo;

#ifdef _MGRM_PROCESSES
    JoinLayer(NAME_DEF_LAYER , "painter" , 0 , 0);
#endif

    CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
    CreateInfo.dwExStyle = WS_EX_NONE;
    CreateInfo.spCaption = "鼠标消息捕获";
    CreateInfo.hMenu = 0;
    CreateInfo.hCursor = GetSystemCursor(0);
    CreateInfo.hIcon = 0;
    CreateInfo.MainWindowProc = PainterWinProc;
    CreateInfo.lx = 0;
    CreateInfo.ty = 0;
    CreateInfo.rx = 240;
    CreateInfo.by = 320;
    CreateInfo.iBkColor = COLOR_lightwhite;
    CreateInfo.dwAddData = 0;
    CreateInfo.hHosting = HWND_DESKTOP;

    hMainWnd = CreateMainWindow (&CreateInfo);

    if (hMainWnd == HWND_INVALID)
        return -1;

    ShowWindow(hMainWnd, SW_SHOWNORMAL);

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup (hMainWnd);

    return 0;
}







#define IDC_LAMIAN 101
#define IDC_CHOUDOUFU 102
#define IDC_JIANBING 103
#define IDC_MAHUA 104
#define IDC_SHUIJIAO 105
#define IDC_XIAN 110
#define IDC_LA 111
#define IDC_PROMPT 200
static DLGTEMPLATE DlgYourTaste =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	120, 100, 300, 280,
	"你喜欢吃哪种风味的小吃",
	0, 0,
	12, NULL,
	0
};

static CTRLDATA CtrlYourTaste[] =
{
	{
		"static",
		WS_VISIBLE | SS_GROUPBOX,
		16, 10, 130, 160,
		IDC_STATIC,
		"可选小吃",
		0
		},
	{
		"button",
		/* 使用 BS_CHECKED，初始时使其选中 */
		WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CHECKED | WS_TABSTOP | WS_GROUP,
		36, 38, 88, 20,
		IDC_LAMIAN,
		"西北拉面",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_AUTORADIOBUTTON,
		36, 64, 88, 20,
		IDC_CHOUDOUFU,
		"长沙臭豆腐",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_AUTORADIOBUTTON,
		36, 90, 88, 20,
		IDC_JIANBING,
		"山东煎饼",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_AUTORADIOBUTTON,
		36, 116, 88, 20,
		IDC_MAHUA,
		"天津麻花",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_AUTORADIOBUTTON,
		36, 142, 100, 20,
		IDC_SHUIJIAO,
		"成都红油水饺",
		0
	},
	{
		"static",
		WS_VISIBLE | SS_GROUPBOX | WS_GROUP,
		160, 10, 124, 160,
		IDC_STATIC,
		"口味",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_AUTOCHECKBOX,
		170, 38, 88, 20,
		IDC_XIAN,
		"偏咸",
		0
	},
	{
		"button",
		/* 使用 BS_CHECKED，初始时使其选中 */
		WS_VISIBLE | BS_AUTOCHECKBOX | BS_CHECKED,
		170, 64, 88, 20,
		IDC_LA,
		"偏辣",
		0
	},
	{
		"static",
		WS_VISIBLE | SS_LEFT | WS_GROUP,
		16, 180, 360, 20,
		IDC_PROMPT,
		"西北拉面是面食中的精品，但街上的兰州拉面除外！ ",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,
		80, 220, 95, 28,
		IDOK,
		"确定",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
		185, 220, 95, 28,
		IDCANCEL,
		"取消",
		0
	},
};

static char* prompts [] = {
	"西北拉面是面食中的精品，但街上的兰州拉面除外！ ",
	"长沙臭豆腐口味很独特，一般人适应不了。 ",
	"山东煎饼很难嚼 :(",
	"天津麻花很脆，很香！ ",
	"成都的红油水饺可真好吃啊！想起来就流口水。 ",
};

static void MINI_TEST_ButtonProc (HWND hwnd, int id, int nc, DWORD add_data)
{
	/* 用户选择不同的小吃时， 在下面的静态框中显示针对这种小吃的提示信息 */
	if (nc == BN_CLICKED) {
		SetWindowText(GetDlgItem (GetParent (hwnd), IDC_PROMPT), prompts [id - IDC_LAMIAN]);
	}
}

static int MINI_TEST_ButtonDialogBoxProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case MSG_INITDIALOG:
	{
		int i;
		/* 为小吃单选钮设定通知回调函数 */
		for (i = IDC_LAMIAN; i <= IDC_SHUIJIAO; i++)
			SetNotificationCallback (GetDlgItem (hDlg, i), MINI_TEST_ButtonProc);
		}
		 return 1;
		case MSG_COMMAND:
			switch (wParam) {
				case IDOK:
				case IDCANCEL:
					EndDialog (hDlg, wParam);
					break;
				}
			break;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}
int MINI_TEST_BUTTON(void)
{

	DlgYourTaste.controls = CtrlYourTaste;
	DialogBoxIndirectParam (&DlgYourTaste, HWND_DESKTOP, MINI_TEST_ButtonDialogBoxProc, 0L);
	return 0;

}

















#define IDL_DIR 100
#define IDL_FILE 110
#define IDC_PATH 120
/* 定义对话框模板 */
static DLGTEMPLATE DlgDelFiles =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	100, 100, 304, 225,
	"删除文件",
	0, 0,
	7, NULL,
	0
};

static CTRLDATA CtrlDelFiles[] =
{
	{
		CTRL_STATIC,
		WS_VISIBLE | SS_SIMPLE,
		10, 10, 130, 15,
		IDC_STATIC,
		"目录列表框",
		0
	},
	/* 这个列表框中显示目录项 */
	{
		CTRL_LISTBOX,
		WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY,
		10, 30, 130, 100,
		IDL_DIR,
		"",
		0
	},
	{
		CTRL_STATIC,
		WS_VISIBLE | SS_SIMPLE,
		150, 10, 130, 15,
		IDC_STATIC,
		"文件列表框",
		0
	},
	/* 这个列表框中显示文件，前面带一个检查框 */
	{
		CTRL_LISTBOX,
		WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_AUTOCHECKBOX,
		150, 30, 130, 100,
		IDL_FILE,
		"",
		0
	},
	/* 这个静态框用来显示当前路径信息 */
	{
		CTRL_STATIC,
		WS_VISIBLE | SS_SIMPLE,
		10, 150, 290, 15,
		IDC_PATH,
		"路径： ",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,
		10, 170, 130, 25,
		IDOK,
		"删除",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
		150, 170, 130, 25,
		IDCANCEL,
		"取消",
		0
	},
};


/* 这个函数获取当前目录下的所有目录项，分别填到目录列表框和文件列表框中 */
static void MINI_TEST_ListFillBoxes(HWND hDlg, const char* path)
{
	struct dirent* dir_ent;
	DIR* dir;
	struct stat ftype;
	char fullpath [PATH_MAX + 1];
	SendDlgItemMessage (hDlg, IDL_DIR, LB_RESETCONTENT, 0, (LPARAM)0);
	SendDlgItemMessage (hDlg, IDL_FILE, LB_RESETCONTENT, 0, (LPARAM)0);
	SetWindowText (GetDlgItem (hDlg, IDC_PATH), path);

	if ((dir = opendir (path)) == NULL)
		return;

	while ( (dir_ent = readdir ( dir )) != NULL ) {
		/* Assemble full path name. */
		strncpy (fullpath, path, PATH_MAX);
		strcat (fullpath, "/");
		strcat (fullpath, dir_ent->d_name);
		if (stat (fullpath, &ftype) < 0 ) {
		continue;
	}

	if (S_ISDIR (ftype.st_mode))
		SendDlgItemMessage (hDlg, IDL_DIR, LB_ADDSTRING, 0, (LPARAM)dir_ent->d_name);
	else if (S_ISREG (ftype.st_mode)) {
		/* 使用检查框的列表框，需要使用下面的结构 */
		LISTBOXITEMINFO lbii;
		lbii.string = dir_ent->d_name;
		lbii.cmFlag = CMFLAG_BLANK;
		lbii.hIcon = 0;
		SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);
		}
	}
	closedir (dir);
}


static void MINI_TEST_ListDirNotifProc (HWND hwnd, int id, int nc, DWORD add_data)
{
	/* 用户双击目录名或者按下 ENTER 键时，进入对应的目录 */
	if (nc == LBN_DBLCLK || nc == LBN_ENTER) {
		int cur_sel = SendMessage (hwnd, LB_GETCURSEL, 0, 0L);
		if (cur_sel >= 0) {
			char cwd [MAX_PATH + 1];
			char dir [MAX_NAME + 1];
			GetWindowText (GetDlgItem (GetParent (hwnd), IDC_PATH), cwd, MAX_PATH);
			SendMessage (hwnd, LB_GETTEXT, cur_sel, (LPARAM)dir);
			if (strcmp (dir, ".") == 0)
				return;
			strcat (cwd, "/");
			strcat (cwd, dir);
			/* 重新填充两个列表框 */
			MINI_TEST_ListFillBoxes(GetParent (hwnd), cwd);
		}
	}
}

static void MINI_TEST_ListFileNotifProc (HWND hwnd, int id, int nc, DWORD add_data)
{
/* Do nothing */
}

static void prompt (HWND hDlg)
{
	int i;
	char files [1024] = "你选择要删除的文件是： \n";
	/* 获取所有勾选的文件 */
	for (i = 0; i < SendDlgItemMessage (hDlg, IDL_FILE, LB_GETCOUNT, 0, 0L); i++) {
		char file [MAX_NAME + 1];
		int status = SendDlgItemMessage (hDlg, IDL_FILE, LB_GETCHECKMARK, i, 0);
		if (status == CMFLAG_CHECKED) {
			SendDlgItemMessage (hDlg, IDL_FILE, LB_GETTEXT, i, (LPARAM)file);
			strcat (files, file);
			strcat (files, "\n");
		}
	}
	/* 提示用户 */
	MessageBox (hDlg, files, "确认删除", MB_OK | MB_ICONINFORMATION);
	/* 在这里把那些文件真正删除！ */
}



static int MINI_TEST_DelFilesBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
		case MSG_INITDIALOG:
		{
			char cwd[MAX_PATH + 1];
			SetNotificationCallback(GetDlgItem (hDlg, IDL_DIR), MINI_TEST_ListDirNotifProc);
			SetNotificationCallback(GetDlgItem (hDlg, IDL_FILE), MINI_TEST_ListFileNotifProc);
			MINI_TEST_ListFillBoxes(hDlg, getcwd (cwd, MAX_PATH));
			return 1;
		}
		case MSG_COMMAND:
			switch (wParam) {
			case IDOK:
				prompt (hDlg);
			case IDCANCEL:
				EndDialog (hDlg, wParam);
				break;
			}
		break;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}
int MINI_TEST_list(void)
{

	DlgDelFiles.controls = CtrlDelFiles;


	DialogBoxIndirectParam (&DlgDelFiles, HWND_DESKTOP, MINI_TEST_DelFilesBoxProc, 0L);
	return 0;
}















static HWND MINI_TEST_CreateProgressWin(HWND hParentWnd, char * title, char * label, int id, int range)
{
	HWND hwnd;
	MAINWINCREATE CreateInfo;
	int ww, wh;
	HWND hStatic, hProgBar;
	/* 根据窗口客户区宽度计算窗口宽度 */
	ww = ClientWidthToWindowWidth (WS_CAPTION | WS_BORDER, 400);
	/* 根据窗口客户区高度计算窗口高度 */
	wh = ClientHeightToWindowHeight (WS_CAPTION | WS_BORDER,(range > 0) ? 70 : 35, FALSE);

	/* 创建主窗口 */
	CreateInfo.dwStyle = WS_ABSSCRPOS | WS_CAPTION | WS_BORDER | WS_VISIBLE;
	CreateInfo.dwExStyle = WS_EX_NONE;
	CreateInfo.spCaption = title;
	CreateInfo.hMenu = 0;
	CreateInfo.hCursor = GetSystemCursor(IDC_WAIT);
	CreateInfo.hIcon = 0;
	/* 该主窗口的窗口过程取默认的主窗口过程 */
	CreateInfo.MainWindowProc = DefaultMainWinProc;
#ifndef _LITE_VERSION
	CreateInfo.lx = (GetGDCapability(HDC_SCREEN, GDCAP_MAXX) - ww) >> 1;
	CreateInfo.ty = (GetGDCapability(HDC_SCREEN, GDCAP_MAXY) - wh) >> 1;
#else
	CreateInfo.lx = g_rcExcluded.left + (RECTW(g_rcExcluded) - ww) >> 1;
	CreateInfo.ty = g_rcExcluded.top + (RECTH(g_rcExcluded) - wh) >> 1;
#endif
	CreateInfo.rx = CreateInfo.lx + ww;
	CreateInfo.by = CreateInfo.ty + wh;
	CreateInfo.iBkColor = COLOR_lightgray;
	CreateInfo.dwAddData = 0L;
	CreateInfo.hHosting = hParentWnd;
	hwnd = CreateMainWindow (&CreateInfo);
	if (hwnd == HWND_INVALID)
		return hwnd;
	/* 在主窗口中创建提示用静态框控件 */
	hStatic = CreateWindowEx ("static",
	label,
	WS_VISIBLE | SS_SIMPLE,
	WS_EX_USEPARENTCURSOR,
	IDC_STATIC,
	10, 10, 380, 16, hwnd, 0);
	/* 在主窗口中创建进度条控件 */

	if (range > 0) {
		hProgBar = CreateWindowEx ("progressbar",
		NULL,
		WS_VISIBLE,
		WS_EX_USEPARENTCURSOR,
		id,
		10, 30, 380, 30, hwnd, 0);
		SendDlgItemMessage (hwnd, id, PBM_SETRANGE, 0, range);
	} else
		hProgBar = HWND_INVALID;

	/* 更新控件 */
	UpdateWindow (hwnd, TRUE);
	/* 返回主窗口句柄 */
	return hwnd;
}



static void MINI_TEST_DestroyProgressWin(HWND hwnd)
{
	/* 销毁控件以及主窗口 */
	DestroyAllControls (hwnd);
	DestroyMainWindow (hwnd);
	ThrowAwayMessages (hwnd);
	MainWindowThreadCleanup (hwnd);
}

int MINI_TEST_ProgressBar(void)
{
	int i, sum;
	HCURSOR hOldCursor;
	HWND hwnd;

	/* 设置“沙漏”鼠标，以表示系统正忙 */
	hOldCursor = SetDefaultCursor (GetSystemCursor (IDC_WAIT));
	/* 创建进度条窗口，指定进度条控件的标识符和范围值 */
	hwnd = MINI_TEST_CreateProgressWin(HWND_DESKTOP, "进度条", "正在计算，请稍候...", 100, 2000);

	while (HavePendingMessage (hwnd)) {
		MSG msg;
		GetMessage (&msg, hwnd);
		DispatchMessage (&msg);
	}

	/* 进入长时计算过程，完成大循环时更新进度条控件的位置 */
	for (i = 0; i < 2000; i++) {
	unsigned long j;
	if (i % 100 == 0) {
		SendDlgItemMessage (hwnd, 100, PBM_SETPOS, i, 0L);
		while (HavePendingMessage (hwnd)) {
			MSG msg;
			GetMessage (&msg, hwnd);
			DispatchMessage (&msg);
		}
	}
	sum = i*5000;
	for (j = 0; j < 500000; j++)
		sum *= j;
		sum += sum;
	}
	/* 销毁进度条窗口 */
	MINI_TEST_DestroyProgressWin(hwnd);
	/* 恢复原有鼠标 */
	SetDefaultCursor (hOldCursor);
	return 0;
}
















#define IDC_MC 100
#define IDC_OK 200
#if 0
/* 对话框模板：只有两个控件：月历控件和“确定”按钮 */
static CTRLDATA CtrlTime[]=
{
	{
		"monthcalendar",
		WS_CHILD | WS_VISIBLE | MCS_NOTIFY | MCS_CHN,//MCS_ENG_S,//
		10, 10, 240, 180,
		IDC_MC,
		"",
		0
	},
	{
		"button",
		WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		260, 180, 50, 22,
		IDC_OK,
		"确定",
		0
	}
};

static DLGTEMPLATE DlgTime =
{
	WS_VISIBLE | WS_CAPTION | WS_BORDER,
	WS_EX_NONE,
	0, 0, 320, 240,
	"约会时间",
	0, 0,
	2, CtrlTime,
	0
};

static int MINI_TEST_TimeWinProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case MSG_COMMAND:
	{
		int id = LOWORD(wParam);
		if (id == IDC_OK) {
			char info[100];
			SYSTEMTIME date;
			/* 获取月历控件中的当前日期 */
			SendMessage (GetDlgItem(hDlg, IDC_MC), MCM_GETCURDATE, 0, (LPARAM)&date);
			sprintf (info, "你定于%d 年%d 月%d 日会见总统!",
				date.year, date.month, date.day);
			MessageBox (hDlg, info, "约会", MB_OK | MB_ICONINFORMATION);
			EndDialog (hDlg, 0);
		}
	}
	break;
	case MSG_CLOSE:
	{
		EndDialog (hDlg, 0);
	}
	return 0;
	}

	return DefaultDialogProc (hDlg, message, wParam, lParam);
}


#endif

static int CreateMonthProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
	char s8Utf8[64];
	static HWND Wind, buttonWind;
	//RECT client;

	snprintf(s8Utf8, sizeof(s8Utf8), "你好世界你好");

    switch (message) {
			case MSG_CREATE:
			Wind = CreateWindow(CTRL_MONTHCALENDAR, "", WS_CHILD | WS_VISIBLE | MCS_NOTIFY | MCS_CHN,
	               IDC_MC, 10, 10, 320, 320, hWnd, 0);

			PLOGFONT log_font=CreateLogFont(NULL,"song","GB2312",FONT_WEIGHT_REGULAR,FONT_SLANT_ROMAN,FONT_FLIP_NIL,FONT_OTHER_AUTOSCALE,
								FONT_UNDERLINE_NONE,FONT_STRUCKOUT_NONE,16,0);
			SetWindowFont(Wind, log_font);


			buttonWind = CreateWindow(CTRL_BUTTON, "确定", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
	               IDC_OK, 260, 400, 50, 30, hWnd, 0);

	//PLOGFONT log_font=CreateLogFont(NULL,"song","GB2312",FONT_WEIGHT_REGULAR,FONT_SLANT_ROMAN,FONT_FLIP_NIL,FONT_OTHER_AUTOSCALE,
	//					FONT_UNDERLINE_NONE,FONT_STRUCKOUT_NONE,16,0);

			PLOGFONT utf8 = CreateLogFontByName("ttf-simhei-rrncnn-0-0-UTF-8");
			if(utf8 == NULL) {
				QLOG(TDBG, "字体为空\n");
			}
			SetWindowFont(buttonWind, utf8);



		break;

        case MSG_PAINT:
           	hdc = BeginPaint(hWnd);
			//TextOut(hdc, 40, 40, s8Utf8);

            EndPaint (hWnd, hdc);
        	return 0;

		case MSG_COMMAND:
		{
			int id = LOWORD(wParam);
			if (id == IDC_OK) {
				char info[150];
				SYSTEMTIME date;
				/* 获取月历控件中的当前日期 */
				//SendMessage (GetDlgItem(hWnd, IDC_MC), MCM_GETCURDATE, 0, (LPARAM)&date);
				PLOGFONT utf8 = CreateLogFontByName("ttf-simhei-rrncnn-0-0-UTF-8");
				if(utf8 == NULL) {
					QLOG(TDBG, "字体为空\n");
				}
				SetWindowFont(buttonWind, utf8);

				SendMessage (GetDlgItem(hWnd, IDC_MC), MCM_GETCURDATE, 0, (LPARAM)&date);

				//SendMessage (hWnd, MCM_GETCURDATE, 0, (LPARAM)&date);
				sprintf (info, "你定于%d年%d月%d日约会",
					date.year, date.month, date.day);
				MessageBox (hWnd, info, "约会", MB_OK | MB_ICONINFORMATION);
				EndDialog (hWnd, 0);
			}
		}
		break;
        case MSG_CLOSE:
			QLOG(TDBG, "结束主界面\n");
			//DestroyLogFont(pstFont);
            DestroyMainWindow (hWnd);
            PostQuitMessage (hWnd);
            return 0;
    }

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}


int MINI_TEST_Month(void)
{
#if 1


		MSG Msg;
		HWND hMainWnd;
		MAINWINCREATE CreateInfo;
		unsigned char bRet;
		CreateInfo.dwStyle = WS_CAPTION | WS_BORDER |
							WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_SYSMENU;
		CreateInfo.dwExStyle = WS_EX_IMECOMPOSE;
		CreateInfo.spCaption = "月历";
		CreateInfo.hMenu = 0;
		CreateInfo.hCursor = GetSystemCursor(0);
		CreateInfo.hIcon = 0;
		CreateInfo.MainWindowProc = CreateMonthProc;
		CreateInfo.lx = 20;
		CreateInfo.ty = 20;
		CreateInfo.rx = 700;
		CreateInfo.by = 570;
		CreateInfo.iBkColor = COLOR_lightgray;
		CreateInfo.dwAddData = 0;

		CreateInfo.hHosting = HWND_DESKTOP;

		hMainWnd = CreateMainWindow (&CreateInfo);

		if (hMainWnd == HWND_INVALID)
		return -1;


		bRet = ShowWindow(hMainWnd, SW_SHOW);
		if(FALSE == bRet) {
			QLOG(ERR, "MINI_API_ShowOrHideWindow failed\n");
			return -1;
		} else if(TRUE == bRet) {
			QLOG(TDBG, "成功显示窗口\n");
		}
		ShowWindow(hMainWnd, SW_HIDE);
		ShowWindow(hMainWnd, SW_SHOW);


		while(GetMessage(&Msg, hMainWnd)) {
				TranslateMessage (&Msg);
				DispatchMessage (&Msg);
		}
		QLOG(TDBG, "退出窗口\n");

		MainWindowThreadCleanup(hMainWnd);



#else



    DlgTime.controls = CtrlTime;

    DialogBoxIndirectParam (&DlgTime, HWND_DESKTOP, MINI_TEST_TimeWinProc, 0L);
	//DialogBoxIndirectParam (&DlgTime, Win, MINI_TEST_TimeWinProc, 0L);


#endif


    return 0;
}








#define IDC_HOUR 100
#define IDC_MINUTE 110
#define IDC_SECOND 120
#define IDL_DAXIA 200
#define IDC_COM_PROMPT 300
/* 定义对话框模板 */
static DLGTEMPLATE DlgMyDate =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	100, 100, 304, 135,
	"约会大侠",
	0, 0,
	9, NULL,
	0
};
static CTRLDATA CtrlMyDate[] =
{
	{
		"static",
		WS_CHILD | SS_RIGHT | WS_VISIBLE,
		10, 20, 50, 20,
		IDC_STATIC,
		"我打算于",
		0
	},
	/* 用来显示小时的旋钮数字框 */
	{
		CTRL_COMBOBOX,
		WS_CHILD | WS_VISIBLE |
		CBS_READONLY | CBS_AUTOSPIN | CBS_AUTOLOOP | CBS_EDITBASELINE,
		60, 18, 40, 20,
		IDC_HOUR,
		"",
		0
	},
	{
		"static",
		WS_CHILD | SS_CENTER | WS_VISIBLE,
		100, 20, 20, 20,
		IDC_STATIC,
		"时",
		0
	},
	/* 用来显示分钟的旋钮数字框 */
	{
		CTRL_COMBOBOX,
		WS_CHILD | WS_VISIBLE |
		CBS_READONLY | CBS_AUTOSPIN | CBS_AUTOLOOP | CBS_EDITBASELINE,
		120, 18, 40, 20,
		IDC_MINUTE,
		"",
		0
	},
	{
		"static",
		WS_CHILD | SS_CENTER | WS_VISIBLE,
		160, 20, 30, 20,
		IDC_STATIC,
		"去找",
		0
	},
	/* 列各位大侠的大名 */
	{
		CTRL_COMBOBOX,
		WS_VISIBLE | CBS_DROPDOWNLIST | CBS_NOTIFY,
		190, 20, 100, 20,
		IDL_DAXIA,
		"",
		80
	},
	/* 显示大侠特点 */
	{
		"static",
		WS_CHILD | SS_RIGHT | WS_VISIBLE,
		10, 50, 280, 20,
		IDC_COM_PROMPT,
		"This is",
		0
	},
	{
		CTRL_BUTTON,
		WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,
		10, 70, 130, 25,
		IDOK,
		"确定",
		0
	},
	{
		"button",
		WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
		150, 70, 130, 25,
		IDCANCEL,
		"取消",
		0
	},
};

static const char* daxia [] =
{
	"黄药师",
	"欧阳锋",
	"段皇爷",
	"洪七公",
	"周伯通",
	"郭靖",
	"黄蓉",
};
static const char* daxia_char [] =
{
	"怪僻",
	"恶毒",
	"假慈悲",
	"一身正气",
	"调皮，不负责任",
	"傻乎乎",
	"乖巧",
};

static void MINI_TEST_CommBoboxDaxiaNotifProc(HWND hwnd, int id, int nc, DWORD add_data)
{
	if (nc == CBN_SELCHANGE) {
	/* 根据当前选择的大侠，显示对应的性格特点 */
	int cur_sel = SendMessage (hwnd, CB_GETCURSEL, 0, 0);
		if (cur_sel >= 0) {
			SetWindowText (GetDlgItem (GetParent(hwnd), IDC_COM_PROMPT), daxia_char [cur_sel]);
		}
	}
}

static void MINI_TEST_ComBoboxPrompt(HWND hDlg)
{
	char date [1024];
	/* 总结约会内容 */
	int hour = SendDlgItemMessage(hDlg, IDC_HOUR, CB_GETSPINVALUE, 0, 0);
	int min = SendDlgItemMessage(hDlg, IDC_MINUTE, CB_GETSPINVALUE, 0, 0);
	int sel = SendDlgItemMessage(hDlg, IDL_DAXIA, CB_GETCURSEL, 0, 0);

	sprintf (date, "你打算于今日 %02d:%02d 去见那个%s 的%s", hour, min,
	daxia_char [sel], daxia [sel]);
	MessageBox (hDlg, date, "约会内容", MB_OK | MB_ICONINFORMATION);
}

static int MINI_TEST_MyDateBoxProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	int i;
	switch (message) {
		case MSG_INITDIALOG:
			/* 设定小时旋钮框的范围在 0~23，数字以 %02d 的格式显示 */
			SendDlgItemMessage(hDlg, IDC_HOUR, CB_SETSPINRANGE, 0, 23);
			SendDlgItemMessage(hDlg, IDC_HOUR, CB_SETSPINFORMAT, 0, (LPARAM)"%02d");

			/* 设定当前值为 20 */
			SendDlgItemMessage(hDlg, IDC_HOUR, CB_SETSPINVALUE, 20, 0);
			/* 设定步进值和快速步进值均为 1 */
			SendDlgItemMessage(hDlg, IDC_HOUR, CB_SETSPINPACE, 1, 1);

			/* 设定小时旋钮框的范围在 0~59，数字以 %02d 的格式显示 */
			SendDlgItemMessage(hDlg, IDC_MINUTE, CB_SETSPINRANGE, 0, 59);
			SendDlgItemMessage(hDlg, IDC_MINUTE, CB_SETSPINFORMAT, 0, (LPARAM)"%02d");

			/* 设定当前值为 0 */
			SendDlgItemMessage(hDlg, IDC_MINUTE, CB_SETSPINVALUE, 0, 0);
			/* 设定步进值为 1，快速步进值为 2 */
			SendDlgItemMessage(hDlg, IDC_MINUTE, CB_SETSPINPACE, 1, 2);

			/* 加入各位大侠的名字 */
			for (i = 0; i < 7; i++) {
				SendDlgItemMessage(hDlg, IDL_DAXIA, CB_ADDSTRING, 0, (LPARAM)daxia [i]);
			}
			/* 设定通知回调函数 */
			SetNotificationCallback (GetDlgItem (hDlg, IDL_DAXIA), MINI_TEST_CommBoboxDaxiaNotifProc);
			/* 设定大侠名字和性格特点的初始值 */
			SendDlgItemMessage(hDlg, IDL_DAXIA, CB_SETCURSEL, 0, 0);
			SetWindowText (GetDlgItem (hDlg, IDC_COM_PROMPT), daxia_char [0]);
			return 1;
		case MSG_COMMAND:
			switch (wParam) {
				case IDOK:
					/* 显示当前选择 */
					MINI_TEST_ComBoboxPrompt (hDlg);
				case IDCANCEL:
					EndDialog (hDlg, wParam);
					break;
			}
		break;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}

int MINI_TEST_CommonBobox(void)
{

	DlgMyDate.controls = CtrlMyDate;
	DialogBoxIndirectParam (&DlgMyDate, HWND_DESKTOP, MINI_TEST_MyDateBoxProc, 0L);
	return 0;
}











#define IDC_ICONVIEW 100
#define IDC_BT 200
#define IDC_BT2 300
#define IDC_BT3 400
#define IDC_BT4 500
#define IDC_ADD 600
#define IDC_DELETE 601
static HWND hIconView;
static BITMAP myicons [12];

static const char* iconfiles[12] =
{
	"./sample/res/res/acroread.png",
	"./sample/res/res/icons.png",
	"./sample/res/res/looknfeel.png",
	"./sample/res/res/package_games.png",
	"./sample/res/res/tux.png",
	"./sample/res/res/xemacs.png",
	"./sample/res/res/gimp.png",
	"./sample/res/res/kpilot.png",
	"./sample/res/res/multimedia.png",
	"./sample/res/res/realplayer.png",
	"./sample/res/res/usb.png",
	"./sample/res/res/xmms.png"
};
static const char *iconlabels[12] =
{
	"acroread",
	"icons",
	"looknfeel",
	"games",
	"tux",
	"xemacs",
	"gimp",
	"kpilot",
	"multimedia",
	"realplayer",
	"usb",
	"xmms"
};

#if 0
static void myDrawItem(HWND hWnd, GHANDLE hsvi, HDC hdc, RECT *rcDraw)
{
	const PBITMAP pbmp = (PBITMAP)iconview_get_item_bitmap (hsvi);
	const char *label = (const char*)iconview_get_item_label (hsvi);
	SetBkMode (hdc, BM_TRANSPARENT);
	SetTextColor (hdc, PIXEL_black);

	if (iconview_is_item_hilight(hWnd, hsvi)) {
		SetBrushColor (hdc, PIXEL_blue);
	}else {
		SetBrushColor (hdc, PIXEL_lightwhite);
	}
	FillBox (hdc, rcDraw->left, rcDraw->top, RECTWP(rcDraw), RECTHP(rcDraw));
	SetBkColor (hdc, PIXEL_blue);
	if (label) {
		RECT rcTxt = *rcDraw;
		rcTxt.top = rcTxt.bottom - GetWindowFont (hWnd)->size * 2;
		rcTxt.left = rcTxt.left - (GetWindowFont (hWnd)->size) + 2;
		DrawText (hdc, label, -1, &rcTxt, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	}
	FillBoxWithBitmap (hdc, rcDraw->left, rcDraw->top, 0, 0, pbmp);
}
#endif
static int MINI_TEST_SpriteIconBookProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case MSG_INITDIALOG:
	{
		IVITEMINFO ivii;
		static int i = 0, j = 0;
		hIconView = GetDlgItem (hDlg, IDC_ICONVIEW);
		SetWindowBkColor (hIconView, PIXEL_lightwhite);
		//SendMessage (hIconView, IVM_SETITEMDRAW, 0, (LPARAM)myDrawItem);
		SendMessage (hIconView, IVM_SETITEMSIZE, 55, 65);
		//SendMessage (hIconView, IVM_SETITEMSIZE, 35, 35);
		for (j = 0; j < 3; j ++) {
			for (i = 0; i < TABLESIZE(myicons); i++) {
			memset (&ivii, 0, sizeof(IVITEMINFO));
			ivii.bmp = &myicons[i];
			ivii.nItem = 12 * j + i;
			ivii.label = iconlabels[i];
			ivii.addData = (DWORD)iconlabels[i];
			SendMessage (hIconView, IVM_ADDITEM, 0, (LPARAM)&ivii);
		}
	}
	break;
	}
	case MSG_COMMAND:
	{
		int id = LOWORD (wParam);
		int code = HIWORD (wParam);

		switch (id) {
			case IDC_ICONVIEW:
				if (code == IVN_CLICKED) {
					int sel;
					sel = SendMessage (hIconView, IVM_GETCURSEL, 0, 0);
					printf ("clicking %d\n", sel);
				}
			break;
			case IDC_ADD:
			{
				IVITEMINFO ivii;
				char buff [10];
				int idx;
				int count = SendMessage (hIconView, IVM_GETITEMCOUNT, 0, 0);
				sprintf (buff, "NewIcon%i", count);
				memset (&ivii, 0, sizeof (IVITEMINFO));
				ivii.bmp = &myicons [0];
				ivii.nItem = count;
				ivii.label = buff;
				ivii.addData = (DWORD)"NewIcon";
				idx = SendMessage (hIconView, IVM_ADDITEM, 0, (LPARAM)&ivii);
				SendMessage (hIconView, IVM_SETCURSEL, idx, 1);
				break;
				}
			case IDC_DELETE:
			{
				int sel = SendMessage (hIconView, IVM_GETCURSEL, 0, 0);
				int count = SendMessage (hIconView, IVM_GETITEMCOUNT, 0, 0);
				char *label = NULL;

				if (sel >= 0){
						label = (char *) SendMessage (hIconView, IVM_GETITEMADDDATA, sel, 0);

					if (label && strlen (label))
						printf ("delelete item:%s\n", label);
						SendMessage (hIconView, IVM_DELITEM, sel, 0);
					if (sel == count - 1)
						sel --;
						SendMessage (hIconView, IVM_SETCURSEL, sel, 1);
					}
				break;
				}
			} /* end command switch */
		break;
	}
	case MSG_KEYDOWN:
		if (wParam == SCANCODE_REMOVE) {
			int cursel = SendMessage (hIconView, IVM_GETCURSEL, 0, 0);
			if (cursel >= 0){
				SendMessage (hIconView, IVM_DELITEM, cursel, 0);
				SendMessage (hIconView, IVM_SETCURSEL, cursel, 0);
			}
		}
		break;

	case MSG_CLOSE:
		{
			EndDialog (hDlg, 0);
			return 0;
		}
	} /* end switch */
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}

static CTRLDATA SpriteIconCtrlBook[] =
{
	{
		CTRL_ICONVIEW,
		WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,
		10, 10, 290, 300,
		IDC_ICONVIEW,
		"",
		0
	},
	{
		CTRL_BUTTON,
		WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP,
		90, 330, 50, 30,
		IDC_ADD,
		"Add",
		0
	},
	{
		CTRL_BUTTON,
		WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
		170, 330, 50, 30,
		IDC_DELETE,
		"Delete",
		0
	}
};

static DLGTEMPLATE DlgIcon =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	0, 0, 310, 400,
	"My Friends",
	0, 0,
	TABLESIZE(SpriteIconCtrlBook), SpriteIconCtrlBook,
	0
};




int MINI_TEST_SpriteIcon(void)
{
    int i;


    for (i=0; i<TABLESIZE(myicons); i++) {
        LoadBitmap (HDC_SCREEN, &myicons[i], iconfiles[i]);
    }


    DialogBoxIndirectParam (&DlgIcon, HWND_DESKTOP, MINI_TEST_SpriteIconBookProc, 0L);

    return 0;
}












#define PAGE_VERSION 1
#define PAGE_CPU 2
#define PAGE_MEMINFO 3
#define PAGE_PARTITION 4
#define PAGE_MINIGUI 5
#define IDC_PROPSHEET 100
#define IDC_SYSINFO 100
#define BUF_LEN 10240

/* 定义系统信息属性页的模板 */
static DLGTEMPLATE PageSysInfo =
{
	WS_NONE,
	WS_EX_NONE,
	0, 0, 0, 0,
	"",
	0, 0,
	1, NULL,
	0
};

/*系统信息属性页中只有一个用来显示信息的静态控件 */
static CTRLDATA CtrlSysInfo [] =
{
	{
	CTRL_STATIC,
	WS_VISIBLE | SS_LEFT,
	10, 10, 370, 160,
	IDC_SYSINFO,
	"测试\n 测试\n 测试\n 测试\n 测试\n 测试\n",
	0
	}
};

/* 从指定文件中读取系统信息 */
static size_t read_sysinfo (const char* file, char* buff, size_t buf_len)
{
	size_t size;
	FILE* fp = fopen (file, "r");
	if (fp == NULL) return 0;
	size = fread (buff, 1, buf_len, fp);
	fclose (fp);
	return size;
}



/*
* 初始化和刷新时调用该函数刷新对应的窗口。
* 注意，这个函数被所有的属性页调用。
*/
static void get_systeminfo (HWND hDlg)
{
	int type;
	HWND hwnd;
	char buff [BUF_LEN + 1];
	size_t size = 0;
	/* 根据 type 判断是哪个属性页 */
	type = (int)GetWindowAdditionalData (hDlg);

	/* 获取属性页中静态框的句柄 */
	hwnd = GetDlgItem (hDlg, IDC_SYSINFO);
	buff [BUF_LEN] = 0;
	switch (type) {
	case PAGE_VERSION:
		size = read_sysinfo ("/proc/version", buff, BUF_LEN);
		buff [size] = 0;
		break;
	case PAGE_CPU:
		size = read_sysinfo ("/proc/cpuinfo", buff, BUF_LEN);
		buff [size] = 0;
		break;
	case PAGE_MEMINFO:
		size = read_sysinfo ("/proc/meminfo", buff, BUF_LEN);
		buff [size] = 0;
		break;
	case PAGE_PARTITION:
		size = read_sysinfo ("/proc/partitions", buff, BUF_LEN);
		buff [size] = 0;
		break;
	case PAGE_MINIGUI:
		size = snprintf (buff, BUF_LEN,
"MiniGUI version %d.%d.%d.\n"
"Copyright (C) 1998-2003 Feynman Software and others.\n\n"
"MiniGUI is free software, covered by the GNU General Public License, "
"and you are welcome to change it and/or distribute copies of it "
"under certain conditions. "
"Please visit\n\n"
"http://www.minigui.org\n\n"
"to know the details.\n\n"
"There is absolutely no warranty for MiniGUI.",
		MINIGUI_MAJOR_VERSION, MINIGUI_MINOR_VERSION, MINIGUI_MICRO_VERSION);

	break;
	}
	if (size) {
	SetWindowText (hwnd, buff);
	}
}


/* 所有的属性页使用同一个窗口过程函数 */
static int SysInfoPageProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case MSG_INITPAGE:
		/* 获取属性页中静态框的句柄 */
		get_systeminfo (hDlg);
		break;
	case MSG_SHOWPAGE:
		return 1;
	case MSG_SHEETCMD:
		if (wParam == IDOK)
		/* 用户单击对话框中的“刷新”按钮时，将调用该函数刷新 */
		get_systeminfo (hDlg);
		return 0;
	}
	return DefaultPageProc (hDlg, message, wParam, lParam);
}

static int PropSheetProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case MSG_INITDIALOG:
	{
		HWND pshwnd = GetDlgItem (hDlg, IDC_PROPSHEET);
		PageSysInfo.controls = CtrlSysInfo;
		/* 添加属性页，注意每个属性页具有不同的附加数据 */
		PageSysInfo.caption = "版本信息";
		PageSysInfo.dwAddData = PAGE_VERSION;
		SendMessage (pshwnd, PSM_ADDPAGE, (WPARAM)&PageSysInfo, (LPARAM)SysInfoPageProc);
		PageSysInfo.caption = "CPU 信息";
		PageSysInfo.dwAddData = PAGE_CPU;
		SendMessage (pshwnd, PSM_ADDPAGE, (WPARAM)&PageSysInfo, (LPARAM)SysInfoPageProc);
		PageSysInfo.caption = "内存信息";
		PageSysInfo.dwAddData = PAGE_MEMINFO;
		SendMessage (pshwnd, PSM_ADDPAGE, (WPARAM)&PageSysInfo, (LPARAM)SysInfoPageProc);
		PageSysInfo.caption = "分区信息";
		PageSysInfo.dwAddData = PAGE_PARTITION;
		SendMessage (pshwnd, PSM_ADDPAGE, (WPARAM)&PageSysInfo, (LPARAM)SysInfoPageProc);
		PageSysInfo.caption = "MiniGUI 信息";
		PageSysInfo.dwAddData = PAGE_MINIGUI;
		SendMessage (pshwnd, PSM_ADDPAGE, (WPARAM)&PageSysInfo, (LPARAM)SysInfoPageProc);
		break;
	}

	case MSG_COMMAND:
		switch (wParam) {
		case IDOK:
			/* 用户按“刷新”按钮时，向所有属性表控件发送 PSM_SHEETCMD 消息 */
			SendDlgItemMessage (hDlg, IDC_PROPSHEET, PSM_SHEETCMD, IDOK, 0);
			break;
		case IDCANCEL:
			EndDialog (hDlg, wParam);
			break;
		}
	break;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}


/* 主对话框的模板 */
static DLGTEMPLATE DlgPropSheet =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	0, 0, 410, 275,
	"系统信息",
	0, 0,
	3, NULL,
	0
};

/* 该对话框只有三个控件：属性表、 “刷新”按钮和“关闭”按钮 */
static CTRLDATA CtrlPropSheet[] =
{
	{
		CTRL_PROPSHEET,
		WS_VISIBLE | PSS_COMPACTTAB,
		10, 10, 390, 200,
		IDC_PROPSHEET,
		"",
		0
	},
	{
		CTRL_BUTTON,
		WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,
		10, 220, 140, 25,
		IDOK,
		"刷新",
		0
	},
	{
		CTRL_BUTTON,
		WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
		260, 220, 140, 25,
		IDCANCEL,
		"关闭",
		0
	},
};
int MINI_TEST_PropSheet(void)
{

	DlgPropSheet.controls = CtrlPropSheet;
	DialogBoxIndirectParam (&DlgPropSheet, HWND_DESKTOP, PropSheetProc, 0L);
	return 0;
}









#if 0


#define ID_UP 0x101
#define ID_CB 0x102
#define ID_AB 0x103

#define ID_OP 0x111
#define ID_RN 0x112

#define APP_INFO_FILE   "mginit.rc"
#define MGDT_ST_ICONMENU        ""
#define MGDT_ST_OPEN            "Open"
#define MGDT_ST_ABOUT           "About"
#define MGDT_ST_ABOUTM          "About MiniGUI..."
#define MGDT_ST_REFRESH         "Refresh"

typedef struct _Context
{
    PBITMAP bg;
    HMENU hmenu;
    HMENU icon_menu;
}Context;

typedef struct tagDspItem
{
    BOOL    cdpath;
	RECT    hot_spot_rc;
	RECT    text_rc;
    char    path [PATH_MAX + 1];
    char    name [NAME_MAX + 1];
    char    layer [LEN_LAYER_NAME + 1];
    char    bmp_path [PATH_MAX + NAME_MAX + 1];
    BITMAP  bmp;
} DSPITEM;

typedef struct _ICON_INFO
{
    int      nr_apps;
    int      focus;
    char     bg_path [PATH_MAX + 1];
    DSPITEM* app_items;
}ICON_INFO;

#define START_X 20
#define START_Y 10
#define SPACE   30
#define DEF_WIDTH 64
#define DEF_HEIGHT 64

static ICON_INFO icon_info;

extern DESKTOPOPS mg_dsk_ops;


DESKTOPOPS mg_dsk_ops =
{
	this_init,
	this_deinit,
	this_paint_desktop,
	this_keyboard_handler,
	this_mouse_handler,
	this_customize_desktop_menu,
	this_desktop_menucmd_handler,
};

//桌面定制接口回调函数具体如下：
static void free_dsp_app (void)
{
	int i;
	DSPITEM* item;
	item = icon_info.app_items;
	for (i = 0; i < icon_info.nr_apps; i++, item++) {
	if (item->bmp.bmBits) {
	UnloadBitmap (&item->bmp);
	item->bmp.bmBits = NULL;
	}
	}
	free (icon_info.app_items);
	icon_info.app_items = NULL;
}
static BOOL get_dsp_app (void)
{
	int i;
	DSPITEM* item;
	char section [10];
	int distance_x = START_X;
	int distance_y = START_Y;
	SIZE size;

	if (GetIntValueFromEtcFile (APP_INFO_FILE, "desktop", "app_nr", &icon_info.nr_apps) != ETC_OK)
		return FALSE;

	if (icon_info.nr_apps <= 0)
		return FALSE;

	if (GetValueFromEtcFile (APP_INFO_FILE, "desktop", "bg_pic", icon_info.bg_path, PATH_MAX) != ETC_OK)
		return FALSE;

	if ((icon_info.app_items = (DSPITEM*)calloc (icon_info.nr_apps, sizeof (DSPITEM))) == NULL) {
		return FALSE;
	}

	item = icon_info.app_items;
	for (i = 0; i < icon_info.nr_apps; i++, item++) {
		sprintf (section, "dsp-app%d", i);
		if (GetValueFromEtcFile (APP_INFO_FILE, section, "path", item->path, PATH_MAX) != ETC_OK)
			goto error;
		if (GetValueFromEtcFile (APP_INFO_FILE, section, "name", item->name, NAME_MAX) != ETC_OK)
			goto error;
		if (GetValueFromEtcFile (APP_INFO_FILE, section, "layer", item->layer, LEN_LAYER_NAME) != ETC_OK)
			goto error;
		if (GetValueFromEtcFile (APP_INFO_FILE, section, "pictrue", item->bmp_path, PATH_MAX + NAME_MAX) != ETC_OK)
			goto error;
		if (LoadBitmap (HDC_SCREEN, &item->bmp, item->bmp_path) != ERR_BMP_OK) {
			fprintf (stderr, "desktop load resource:%s error. \n", item->bmp_path);
			goto error;
		}
		item->cdpath = TRUE;
		item->hot_spot_rc.left = distance_x;
		item->hot_spot_rc.right = item->hot_spot_rc.left + DEF_WIDTH;
		item->hot_spot_rc.top = distance_y;
		item->hot_spot_rc.bottom = item->hot_spot_rc.top + DEF_HEIGHT;
		GetTextExtent(HDC_SCREEN, item->name, -1, &size);
		item->text_rc.top = item->hot_spot_rc.bottom;
		item->text_rc.left = (item->hot_spot_rc.right + item->hot_spot_rc.left - size.cx)/2;
		item->text_rc.bottom = item->text_rc.top + size.cy;
		item->text_rc.right = item->text_rc.left + size.cx;
		distance_y += SPACE + RECTH(item->hot_spot_rc);
		if(distance_y + DEF_HEIGHT >= g_rcDesktop.bottom)
		{
			distance_y = START_Y;
			distance_x += SPACE + DEF_WIDTH;
		}
	}
	return TRUE;
error:
	free_dsp_app ();
	return FALSE;
}


static HMENU create_icon_menu (void)
{
	HMENU hmnu;
	MENUITEMINFO mii;
	memset (&mii, 0, sizeof(MENUITEMINFO));
	mii.type = MFT_STRING;
	mii.id = 0;
	mii.typedata = (DWORD)MGDT_ST_ICONMENU;
	hmnu = CreatePopupMenu (&mii);
	memset (&mii, 0, sizeof(MENUITEMINFO));
	mii.type = MFT_STRING ;
	mii.state = 0;
	mii.id = ID_OP;
	mii.typedata = (DWORD)MGDT_ST_OPEN;
	InsertMenuItem(hmnu, 2, TRUE, &mii);
	memset (&mii, 0, sizeof(MENUITEMINFO));
	mii.type = MFT_STRING ;
	mii.state = 0;
	mii.id = ID_AB;
	mii.typedata = (DWORD)MGDT_ST_ABOUT;
	InsertMenuItem(hmnu, 3, TRUE, &mii);
	return hmnu;
}

//在初始化中读取桌面的相关资源，并创建图片菜单
static void* this_init(void)
{
	Context *con = malloc(sizeof(Context));
	get_dsp_app ();
	icon_info.focus = 0xFFFF;
	if(0 != strcmp(icon_info.bg_path, ""))
	{
		con->bg = (PBITMAP)malloc(sizeof(BITMAP));
		LoadBitmapFromFile(HDC_SCREEN, con->bg, icon_info.bg_path);
	}
	else
		con->bg = NULL;
		con->icon_menu = create_icon_menu();
		return (void *)con;
}

//释放内存空间
static void this_deinit(void* context)
{
	if(((Context *)context)->bg)
		UnloadBitmap (((Context *)context)->bg);
		free_dsp_app ();
	if (context != NULL) free(context);
		return;
}

//进行桌面绘制
static void this_paint_desktop(void* context, HDC dc_desktop, const RECT* inv_rc)
{
	PBITMAP bg_bmp = NULL;
	int i = 0;
	DSPITEM* item;

	if(((Context *)context)->bg)
		bg_bmp = ((Context *)context)->bg;
		SelectClipRect (dc_desktop, inv_rc);
	if (bg_bmp) {
		FillBoxWithBitmap (dc_desktop, 0, 0,
		g_rcDesktop.right, g_rcDesktop.bottom, bg_bmp);
	}else {
		SetBrushColor (dc_desktop, PIXEL_blue);
		FillBox(dc_desktop, g_rcDesktop.left, g_rcDesktop.top,
		RECTW(g_rcDesktop), RECTH(g_rcDesktop));
	}

	item = icon_info.app_items;
	for(i = 0; i < icon_info.nr_apps; i++, item++)
		{
		if(i == icon_info.focus)
		{
			SetBrushColor (dc_desktop, PIXEL_darkblue);
			FillBox(dc_desktop, item->hot_spot_rc.left,
			item->hot_spot_rc.top,
			RECTW(item->hot_spot_rc),
			RECTH(item->hot_spot_rc));
		}
		FillBoxWithBitmap (dc_desktop,
		item->hot_spot_rc.left,
		item->hot_spot_rc.top,
		RECTW(item->hot_spot_rc),
		RECTH(item->hot_spot_rc),
		&item->bmp);
		SetBkMode(dc_desktop, BM_TRANSPARENT);
		TextOut(dc_desktop,
		item->text_rc.left, item->text_rc.top, item->name);
	}
}

//桌面按键消息
static void this_keyboard_handler(void* context, int message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case MSG_DT_KEYDOWN:
	break;
	case MSG_DT_KEYUP:
	break;
	}
}
//
static void this_customize_desktop_menu (void* context, HMENU hmnu, int start_pos)
{
	((Context *)context)->hmenu = hmnu;
	MENUITEMINFO mii;
	memset (&mii, 0, sizeof(MENUITEMINFO));
	mii.type = MFT_STRING;
	mii.id = ID_UP;
	mii.typedata = (DWORD)MGDT_ST_REFRESH;
	mii.hsubmenu = 0;

	InsertMenuItem (hmnu, start_pos , TRUE, &mii);
#if 0
	mii.type = MFT_STRING;
	mii.id = ID_CB;
	mii.typedata = (DWORD)"Change BkPicture";
	mii.hsubmenu = 0;
	InsertMenuItem (hmnu, start_pos + 1, TRUE, &mii);
#endif

	mii.type = MFT_STRING;
	mii.id = ID_AB;
	mii.typedata = (DWORD)MGDT_ST_ABOUTM;
	mii.hsubmenu = 0;
	InsertMenuItem (hmnu, start_pos + 1, TRUE, &mii);
}

pid_t exec_app_name (const char* file_name, const char* app_name, const char * argv)
{
	pid_t pid = 0;
	if ((pid = vfork ()) > 0) {
		fprintf (stderr, "new child, pid: %d.\n", pid);
	} else if (pid == 0) {
		if (execl (file_name, app_name, argv, NULL) < 0)
		fprintf(stderr, "execl error\n");
		perror ("execl");
		_exit (1);
	} else {
		perror ("vfork");
	}
	return pid;
}

//桌面鼠标消息
static void this_mouse_handler(void* context, int message, WPARAM wParam, LPARAM lParam)
{
	int x, y;
	int i = 0;
	DSPITEM* item;
	static int old_x = 0, old_y = 0;
	x = LOSWORD (lParam);
	y = HISWORD (lParam);
	switch(message)
	{
	case MSG_DT_LBUTTONDOWN:
	{
		item = icon_info.app_items;
		for(i = 0; i < icon_info.nr_apps; i++, item++)
		{
			if (PtInRect(&item->hot_spot_rc, x, y))
			{
				icon_info.focus = i;
				old_x = x;
				old_y = y;
				SendMessage(HWND_DESKTOP, MSG_ERASEDESKTOP,
				0, (LPARAM)&item->hot_spot_rc);
				break;
			}
		}
		break;
	}
	case MSG_DT_LBUTTONUP:
	{
		icon_info.focus = 0xFFFF;
		SendMessage(HWND_DESKTOP, MSG_ERASEDESKTOP, 0, 0);
		break;
	}
	case MSG_DT_LBUTTONDBLCLK:
	{
		char buff [PATH_MAX + NAME_MAX + 1];
		item = icon_info.app_items;
		for(i = 0; i < icon_info.nr_apps; i++, item++)
		{
			if (PtInRect(&item->hot_spot_rc, x, y))
			{
				if(item->cdpath)
				{
					chdir(item->path);
				}
				strcpy (buff, item->path);
				strcat (buff, item->name);
				exec_app_name(buff, item->name, "-layer");
				break;
			}
		}
		break;
	}
	case MSG_DT_MOUSEMOVE:
	{
		RECT rc;
		if (icon_info.focus == 0xFFFF) break;
			item = icon_info.app_items;

		for(i = 0; i < icon_info.nr_apps; i++, item++)
		{
			if (i == icon_info.focus )
			{
				GetBoundRect(&rc, &item->text_rc, &item->hot_spot_rc);
				item->hot_spot_rc.left += x - old_x;
				item->hot_spot_rc.right += x - old_x;
				item->hot_spot_rc.top += y - old_y;
				item->hot_spot_rc.bottom += y - old_y;
				item->text_rc.left += x - old_x;
				item->text_rc.right += x - old_x;
				item->text_rc.top += y - old_y;
				item->text_rc.bottom += y - old_y;
				old_x = x;
				old_y = y;
				GetBoundRect(&rc, &rc, &item->hot_spot_rc);
				GetBoundRect(&rc, &rc, &item->text_rc);
				SendMessage(HWND_DESKTOP, MSG_ERASEDESKTOP, 0, (LPARAM)&rc);
			}
		}
		break;
	}
	case MSG_DT_RBUTTONUP:
	{
		BOOL flag = FALSE;
		item = icon_info.app_items;
		for(i = 0; i < icon_info.nr_apps; i++, item++)
		{
			if (PtInRect(&item->hot_spot_rc, x, y))
			{
				icon_info.focus = i;
				SendMessage(HWND_DESKTOP, MSG_ERASEDESKTOP,
				0, (LPARAM)&item->hot_spot_rc);
				TrackPopupMenu (((Context *)context)->icon_menu,
				TPM_DEFAULT, x, y, HWND_DESKTOP);
				flag = TRUE;
				break;
			}
		}
		if(!flag)
			TrackPopupMenu (((Context *)context)->hmenu, TPM_DEFAULT, x, y, HWND_DESKTOP);
			break;
		}
	}
}

//
static void this_desktop_menucmd_handler (void* context, int id)
{
	if(!context)
	return;
	if(id == ID_UP)
	{
		DesktopUpdateAllWindow();
	}
#if 0
	else if(id == ID_CB)
	{
	NEWFILEDLGDATA file_data;
	int choise = 0;
	// file_data.IsSave = FALSE;
	strcpy(file_data.filepath,".");
	choise = ShowOpenDialog(HWND_DESKTOP, 50, 50, 300, 200, &file_data);
	if(choise == IDOK)
	{
	if(access(file_data.filefullname, F_OK) < 0)
	{
	printf("file not exist!\n");
	}MiniGUI 3.0 编程指南
	Copyright © by the Feynman Software. All contents is the property of Feynman Software.
	else
	{
	printf("ok!\n");
	}
	}
	}
#endif
	else if(id == ID_AB)
	{
#ifdef _MGMISC_ABOUTDLG
#ifdef _MGRM_THREADS
	OpenAboutDialog ();
#else
	OpenAboutDialog (HWND_DESKTOP);
#endif
#endif
	}
	else if(id == ID_OP)
	{
		int i = 0;
		DSPITEM* item;
		char buff [PATH_MAX + NAME_MAX + 1];
		item = icon_info.app_items;
		for(i = 0; i < icon_info.nr_apps; i++, item++)
		{
			if (i == icon_info.focus)
			{
				if(item->cdpath)
				{
					chdir(item->path);
				}
				strcpy (buff, item->path);
				strcat (buff, item->name);
				exec_app_name(buff, item->name, "-layer");
				icon_info.focus = 0xFFFF;
				break;
			}
		}
	}
	else if(id == ID_RN)
	{
	icon_info.focus = 0xFFFF;
	}
	return;
}

//另外，还有一个配置文件 mginit.rc，通过读取该文件，获得桌面的相关资源，配置文件 mginit.rc 的内容如下：
#if 0
[taskbar]
nr=3
autostart=0
logo=res/feynman.png
[app0]
path=../minesweeper/
name=minesweeper
layer=
tip=Game&of&Minesweaper
icon=res/kmines.gif
[app1]
path=../housekeeper/
name=housekeeper
layer=
tip=Sokoban
icon=res/ksokoban.gif
[app2]
path=../same/
name=same
layer=
tip=Game&of&Same
icon=res/ksame.gif
[desktop]
app_nr=8
bg_pic=res/bk.jpg
[dsp-app0]
path=../minesweeper/
name=minesweeper
layer=
pictrue=res/minesweep.png
[dsp-app1]
path=../housekeeper/
name=housekeeper
layer=
pictrue=res/housekeeper.png
[dsp-app2]
path=../same/
name=same
layer=
pictrue=res/same.png
[dsp-app3]
path=../graphics/
name=graphics
layer=
pictrue=res/graphics.png
[dsp-app4]
path=../font_text/
name=font_text
layer=
pictrue=res/font.png
[dsp-app5]
path=../ctrl_dlg/
name=ctrl_dlg
layer=
pictrue=res/dialog.png
[dsp-app6]
path=../graphics/
name=graphicsex
layer=
pictrue=res/graphicsex.png
[dsp-app7]
path=../dbuff/
name=dbuff
layer=
pictrue=res/thaifont.png
#endif
/*
在主函数里面将初始化好的桌面定制结构体，设置到 MiniGUI 里面。下面的代码在 mginit.c （具体的说明请参考：第 17 章 开
发定制的 MiniGUI-Processes 服务器程序）里面：
*/
int MiniGUIMain (int args, const char* arg[])
{
	struct sigaction siga;
	MSG msg;
	OnNewDelClient = on_new_del_client;
	OnChangeLayer = on_change_layer;
	if (!ServerStartup (0, 0, 0)) {
	fprintf (stderr,
	"Can not start the server of MiniGUI-Processes: mginit.\n");
	return 1;
	}
	SetCustomDesktopOperationSet(&mg_dsk_ops);
	if ((hTaskBar = create_task_bar ()) == HWND_INVALID) {
	fprintf (stderr, "Can not create task bar.\n");
	return 2;
	}

	siga.sa_handler = child_wait;
	siga.sa_flags = 0;
	memset (&siga.sa_mask, 0, sizeof(sigset_t));
	sigaction (SIGCHLD, &siga, NULL);
	while (GetMessage (&msg, hTaskBar)) {
		DispatchMessage (&msg);
	}
	return 0;
}
#endif











#define IDC_EDIT 100
#define IDC_SPINBOX 110
/* 用于编辑框的字体。为了取得较好效果，本程序使用了 TrueType 字体 */
static PLOGFONT timefont;
/* 保存老的编辑框窗口过程 */
static WNDPROC old_edit_proc;
/* 本函数根据当前插入符的位置，修改相应的时间单元值 */
static void on_down_up (HWND hwnd, int offset)
{
	char time [10];
	int caretpos;
	int hour, minute, second;
	GetWindowText (hwnd, time, 8);
	caretpos = SendMessage (hwnd, EM_GETCARETPOS, 0, 0);
	hour = atoi (time);
	minute = atoi (time + 3);
	second = atoi (time + 6);
	if (caretpos > 5) { /* change second */
		/* 在秒的位置 */
		second += offset;
		if (second < 0)
		second = 59;
		if (second > 59)
		second = 0;
	} else if (caretpos > 2) { /* change minute */
		/* 在分的位置 */
		minute += offset;
		if (minute < 0)
		minute = 59;
		if (minute > 59)
		minute = 0;
	} else { /* change hour */
		/* 在时的位置 */
		hour += offset;
		if (hour < 0)
		hour = 23;
		if (hour > 23)
		hour = 0;
	}

	/* 将修改后的时间字符串置于编辑框 */
	sprintf (time, "%02d:%02d:%02d", hour, minute, second);
	SetWindowText (hwnd, time);
	/* 恢复插入符位置 */
	SendMessage (hwnd, EM_SETCARETPOS, 0, caretpos);
}


/* 这是编辑框的子类化窗口过程函数 */
static int TimeEditBox (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
	/* 只处理按键消息。下面这些键按下时，调用 on_down_up 函数修改时间值 */
	if (message == MSG_KEYDOWN) {
		switch (wParam) {
			case SCANCODE_CURSORBLOCKUP:
				on_down_up (hwnd, 1);
				return 0;
			case SCANCODE_CURSORBLOCKDOWN:
				on_down_up (hwnd, -1);
				return 0;
			case SCANCODE_PAGEUP:
				on_down_up (hwnd, 10);
				return 0;
			case SCANCODE_PAGEDOWN:
				on_down_up (hwnd, -10);
				return 0;
			case SCANCODE_CURSORBLOCKLEFT:
			case SCANCODE_CURSORBLOCKRIGHT:
				break;
			default:
				return 0;
		}
	}

	/* 忽略下面两个消息，用户只能通过上面的按键进行操作 */
	if (message == MSG_KEYUP || message == MSG_CHAR)
		return 0;

	return (*old_edit_proc) (hwnd, message, wParam, lParam);
}

static int TimeEditorWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case MSG_CREATE:
		{
		HWND hwnd;
		HDC hdc;
		HWND timeedit, spin;
		SIZE size;
		/* 建立说明性静态框 */
		hwnd = CreateWindow (CTRL_STATIC,
			"This is a time editor.\n\n"
			"Pressing <Down-Arrow>, <Up-Arrow>, <PgDn>, and <PgUp> keys"
			" when the box has input focus will change the time.\n\n"
			"You can also change the time by clicking the SpinBox.\n",
			WS_CHILD | WS_VISIBLE | SS_LEFT,
			IDC_STATIC,
			10, 10, 220, 200, hWnd, 0);

		/* 创建编辑框使用的逻辑字体 */
		timefont = CreateLogFont (NULL, "Arial", "ISO8859-1",
			FONT_WEIGHT_BOOK, FONT_SLANT_ROMAN, FONT_FLIP_NIL,
			FONT_OTHER_NIL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,
			30, 0);


		/* 计算输出时间所用的大小和宽度 */
		hdc = GetClientDC (hWnd);
		SelectFont (hdc, timefont);
		GetTextExtent (hdc, "00:00:00", -1, &size);
		ReleaseDC (hdc);

		/* 按照计算出的值创建编辑框窗口 */
		timeedit = CreateWindow (CTRL_SLEDIT,
			"00:00:00",
			WS_CHILD | WS_VISIBLE | ES_BASELINE,
			IDC_EDIT,
			40, 220, size.cx + 4, size.cy + 4, hWnd, 0);

		/* 设置编辑框字体 */
		SetWindowFont (timeedit, timefont);
		/* 子类化编辑框 */
		old_edit_proc = SetWindowCallbackProc (timeedit, TimeEditBox);
		/* 创建旋钮控件 */
		spin = CreateWindow (CTRL_SPINBOX,
			"",
			WS_CHILD | WS_VISIBLE,
			IDC_SPINBOX,
			40 + size.cx + 6, 220 + (size.cy - 14) / 2, 0, 0, hWnd, 0);

		/*
		* 将旋钮控件的目标窗口设置为编辑框，这样，
		* 当用户单击旋钮时，将模拟 MSG_KEYDOWN 消息
		* 并发送到编辑框。
		*/
		SendMessage (spin, SPM_SETTARGET, 0, timeedit);
		break;
	}
	case MSG_DESTROY:
		DestroyAllControls (hWnd);
		DestroyLogFont (timefont);
		return 0;
	case MSG_CLOSE:
		DestroyMainWindow (hWnd);
		PostQuitMessage (hWnd);
		return 0;
	}
	return DefaultMainWinProc (hWnd, message, wParam, lParam);
}


int MINI_TEST_TimerEditor(void)
{
    MSG Msg;
    HWND hMainWnd;
    MAINWINCREATE CreateInfo;

#ifdef _MGRM_PROCESSES
    JoinLayer(NAME_DEF_LAYER , "timeeditor" , 0 , 0);
#endif

#ifdef _LITE_VERSION
    if (!InitVectorialFonts ()) {
        printf ("InitVectorialFonts: error.\n");
        return 1;
    }
#endif

    CreateInfo.dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE;
    CreateInfo.dwExStyle = WS_EX_IMECOMPOSE;
    CreateInfo.spCaption = CAPTION;
    CreateInfo.hMenu = 0;
    CreateInfo.hCursor = GetSystemCursor(0);
    CreateInfo.hIcon = 0;
    CreateInfo.MainWindowProc = TimeEditorWinProc;
    CreateInfo.lx = 0;
    CreateInfo.ty = 0;
    CreateInfo.rx = MINI_RX;
    CreateInfo.by = MINI_BY;
    CreateInfo.iBkColor = PIXEL_lightwhite;
    CreateInfo.dwAddData = 0;
    CreateInfo.hHosting = HWND_DESKTOP;

    hMainWnd = CreateMainWindow (&CreateInfo);

    if (hMainWnd == HWND_INVALID)
        return 3;

    ShowWindow(hMainWnd, SW_SHOWNORMAL);

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup (hMainWnd);

#ifndef _MGRM_THREADS
    TermVectorialFonts ();
#endif

    return 0;
}












static DLGTEMPLATE EditDlgBoxInputChar =
{
	WS_BORDER | WS_CAPTION,
	WS_EX_NONE,
	0, 0, 400, 220,
	"请键入字母",
	0, 0,
	4, NULL,
	0
};

#define IDC_CHAR 100
#define IDC_CHARS 110

static CTRLDATA EditCtrlInputChar [] =
{
	{
	CTRL_STATIC,
	WS_VISIBLE ,
	10, 10, 380, 18,
	IDC_STATIC,
	"请输入一个字母:",
	0
	},
	{
	CTRL_SLEDIT,
	WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_CENTER,
	10, 40, 80, 25,
	IDC_CHAR,
	NULL,
	0
	},
	{
	//CTRL_MLEDIT,
	CTRL_TEXTEDIT,
	WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_BASELINE | ES_AUTOWRAP,
	10, 80, 380, 70,
	IDC_CHARS,
	NULL,
	0
	},
	{
	CTRL_BUTTON,
	WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
	170, 160, 60, 25,
	IDOK,
	"确定",
	0
	}
};

static void MINI_TEST_EditMyNotifProc(HWND hwnd, int id, int nc, DWORD add_data)
{
	unsigned char buff [256] = {0};

	if (id == IDC_CHAR && nc == EN_CHANGE) {

		/* 将用户在单行编辑框中的输入取出（第一个字母），然后插入到多行编辑框中 */
		GetWindowText (hwnd, (char *)buff, 4);
		/* 将单行编辑框的插入符置于头部，以便覆盖老的字母 */
		SendMessage (hwnd, EM_SETCARETPOS, 0, 0);
		printf("String: %s\n", buff);
		SendMessage (GetDlgItem (GetParent (hwnd), IDC_CHARS), MSG_CHAR, buff[0], 0L);
	}else if (id == IDC_CHARS && nc == EN_CHANGE) {
		GetWindowText (hwnd, (char *)buff, 255);
		printf("String: %s\n", buff);
	}
}

static int MINI_TEST_EditInputCharDialogBoxProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	static PLOGFONT my_font;
	HWND hwnd;
	switch (message) {
	case MSG_INITDIALOG:
		my_font = CreateLogFont (NULL, "fmhei", "ISO8859-1",
				FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN, FONT_FLIP_NIL,
				FONT_OTHER_NIL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,
				20, 0);

		hwnd = GetDlgItem (hDlg, IDC_CHAR);
		/* 将单行编辑框的字体设置为大字体 */
		SetNotificationCallback (hwnd, MINI_TEST_EditMyNotifProc);


			QLOG(TDBG, "初始化键盘输入\n");
			//PLOGFONT gb2312_font = CreateLogFontByName("ttf-simhei-rrncnn-0-0-UTF-8");
			//PLOGFONT gb2312_font = CreateLogFontByName("ttf-simhei-rrncnn-0-0-GB2312");
			//PLOGFONT gb2312_font = CreateLogFont("ttf", "simhei", "UTF-8",FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN,FONT_FLIP_NIL, FONT_OTHER_NIL,
			//				FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,48,0);
			//if(gb2312_font == NULL) {
			//	QLOG(TDBG, "字体为空\n");
			//}
			SetWindowFont(hDlg, gb2312_font);

           // SetNotificationCallback(GetDlgItem (hDlg, IDC_EDT_ADDR), edit_notif_proc);
            sk_ime_hwnd = mgiCreateSoftKeypad(notify_ime_status);
			//GBIMEWindowEx (sk_ime_hwnd, 0, 0, 0, 0, FALSE);
            SetFocusChild(GetDlgItem(hDlg, IDC_EDT_ADDR));

            SetIMEStatus(IME_STATUS_AUTOTRACK, TRUE);
            SetIMEStatus(IME_STATUS_ENCODING, IME_ENCODING_LOCAL);
            SetIMEStatus(IME_STATUS_ENABLED, TRUE);


		/* 模拟 INSERT 键的按下，将单行编辑框的编辑模式设置为覆盖模式 */
		SendMessage (hwnd, MSG_KEYDOWN, SCANCODE_INSERT, 0L);
		return 1;
	case MSG_CLOSE:
		EndDialog (hDlg, IDCANCEL);
		break;
	case MSG_COMMAND:
		switch (wParam) {
			case IDOK:
			case IDCANCEL:
			DestroyLogFont (my_font);
			EndDialog (hDlg, wParam);
			break;
		}
	break;
	}
	return DefaultDialogProc (hDlg, message, wParam, lParam);
}

int MINI_TEST_Edit(void)
{
#ifdef _MGRM_PROCESSES
	JoinLayer(NAME_DEF_LAYER , "edit" , 0 , 0);
#endif
#ifdef _LITE_VERSION
	if (!InitVectorialFonts ()) {
	printf ("InitVectorialFonts: error.\n");
	return 1;
	}
#endif
	EditDlgBoxInputChar.controls = EditCtrlInputChar;
	DialogBoxIndirectParam (&EditDlgBoxInputChar, HWND_DESKTOP, MINI_TEST_EditInputCharDialogBoxProc, 0L);
#ifdef _LITE_VERSION
	TermVectorialFonts ();
#endif
	return 0;
}











static HWND Win = 0;
//unsigned int s32Num = 0;

static int MINI_TEST_MainWindowProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
	char s8Utf8[64];

	snprintf(s8Utf8, sizeof(s8Utf8), "你好世界你好123456");


    switch (message) {

		case MSG_NCCREATE:
			QLOG(TDBG, "创建主界面，初始化字体\n");


			break;


		/* 鼠标移动*/
		case MSG_MOUSEMOVE:
		{
			int x = LOWORD (lParam);
			int y = HIWORD (lParam);
			//s32Num++;
			//if(s32Num%1 == 0) {

				MoveWindow(Win, x, y, 10, 20, FALSE);
			//}

		}

		break;
		case MSG_RBUTTONUP:
		{
			QLOG(TDBG, "鼠标右键被释放\n");
			/*
			CreateWindow(CTRL_BUTTON,
					"",
					WS_CHILD | WS_VISIBLE,//WS_BORDER |
					IDC_ICONVIEW,
					0, 50, 720, 100, hWnd, 0);
					*/
		}
		break;
        case MSG_PAINT:
			//QLOG(TDBG, "创建窗口\n");
           	hdc = BeginPaint(hWnd);

			/* 设置字体颜色*/
			SetTextColor(hdc, COLOR_red);

			/* 设置字体背景为透明*/
			SetBkMode (hdc, BM_TRANSPARENT);
			TextOut(hdc, 40, 40, s8Utf8);

			/* 设置字体背景不为透明*/
			SetBkMode (hdc, BM_OPAQUE);
			TextOut(hdc, 80, 80, s8Utf8);

			/* 设置字体背景为透明*/
			SetBkMode (hdc, BM_TRANSPARENT);
			TextOut(hdc, 40, 120, s8Utf8);

            EndPaint(hWnd, hdc);
        	return 0;
        case MSG_CLOSE:
			QLOG(TDBG, "结束主界面\n");
			//DestroyLogFont(pstFont);
            DestroyMainWindow (hWnd);
            PostQuitMessage(hWnd);
            return 0;
    }

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}

int MINI_TEST_MainWindow(void)
{
	MSG stMsg;
	HWND hMainWnd;
	MAINWINCREATE CreateInfo;
	unsigned char bRet;



	CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
	//CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER;
	CreateInfo.dwStyle = WS_BORDER;
	CreateInfo.dwExStyle = WS_EX_NONE;
	//CreateInfo.dwExStyle = WS_EX_AUTOSECONDARYDC;
	CreateInfo.spCaption = "你好";
	CreateInfo.hMenu = 0;
	CreateInfo.hCursor = GetSystemCursor(0);
	//CreateInfo.hCursor = GetSystemCursor(IDC_NODROP);
	CreateInfo.hIcon = 0;
	CreateInfo.MainWindowProc = MINI_TEST_MainWindowProc;
	CreateInfo.lx = 0;
	CreateInfo.ty = 0;
	//CreateInfo.rx = MINI_RX;
	//CreateInfo.by = MINI_BY;
	CreateInfo.rx = MINI_RX;
	CreateInfo.by = MINI_BY;
	//CreateInfo.iBkColor = COLOR_lightwhite;
	CreateInfo.iBkColor = COLOR_transparent;
	//CreateInfo.iBkColor = COLOR_invalid;
	CreateInfo.dwAddData = 0;
	CreateInfo.hHosting = HWND_DESKTOP;

	//hMainWnd = CreateMainWindow (&CreateInfo);
	hMainWnd = CreateMainWindow(&CreateInfo);

	if (hMainWnd == HWND_INVALID)
		return -1;



	//SetWindowElementAttr(hMainWnd, WE_FGC_WINDOW,COLOR_darkyellow);
	DWORD we_attr = GetWindowElementAttr (hMainWnd, WE_BGC_WINDOW);
	QLOG(TDBG, "we_attr [0x%x] COLOR_transparent [0x%x]\n", we_attr& (~(1 << 12)), COLOR_transparent);
	SetWindowElementAttr(hMainWnd, WE_BGC_WINDOW, COLOR_transparent);
	//SetWindowElementAttr(hMainWnd, WE_FGC_WINDOW,COLOR_transparent);
	//SetWindowBkColor (hMainWnd, 0x7FFF0000);


	HDC hdc = GetDC (hMainWnd);
	LoadBitmap(hdc, &bmp_bkgnd, "sample/res/mouse.png");


#if 1
				Win =CreateWindow(CTRL_STATIC,
								"",
								WS_CHILD | SS_BITMAP | WS_VISIBLE | SS_REALSIZEIMAGE | SS_CENTERIMAGE | WS_EX_TRANSPARENT,
								IDC_STATIC,
								720/2-15, 576/2-15, 15, 20, hMainWnd, (DWORD)&bmp_bkgnd);


#else
				Win = CreateWindow(CTRL_ICONVIEW,
					"",
					WS_CHILD | WS_VISIBLE,//WS_BORDER |
					IDC_ICONVIEW,
					720/2, 576/2, 15, 20, hMainWnd, 0);
			IVITEMINFO ivii;
			memset (&ivii, 0, sizeof(IVITEMINFO));
			ivii.bmp = &myicons;
			ivii.nItem = 0;
			//ivii.label = 0;
			ivii.addData = 0;
			SendMessage (Win, IVM_SETITEMSIZE, 15, 15) ;

			SendMessage(Win, IVM_ADDITEM, 0, (LPARAM)&ivii) ;
#endif
	//SetWindowElementAttr(Win, WE_BGC_WINDOW,COLOR_invalid);
	//SetWindowElementAttr(Win, WE_FGC_WINDOW,0x7FFF0000);
	//SetWindowElementAttr(Win, WE_FGC_WINDOW,COLOR_transparent);
	//SetWindowBkColor (Win, COLOR_transparent);


	//SetWindowMask (Win,(MYBITMAP*) &bmp_bkgnd);


	ShowWindow (Win, SW_SHOW);
	ReleaseDC(hdc);

	bRet = ShowWindow(hMainWnd, SW_SHOW);
	if(FALSE == bRet) {
		QLOG(ERR, "MINI_API_ShowOrHideWindow failed\n");
		return -1;
	} else if(TRUE == bRet) {
		QLOG(TDBG, "成功显示窗口\n");
	}
	//MINI_API_ShowOrHideWindow(hMainWnd, SW_HIDE);
	//MINI_API_ShowOrHideWindow(hMainWnd, SW_SHOW);

	UpdateWindow(hMainWnd, TRUE);



	while(GetMessage(&stMsg, hMainWnd)) {
	        TranslateMessage (&stMsg);
	        DispatchMessage (&stMsg);
	}
	QLOG(TDBG, "退出窗口\n");

	MainWindowThreadCleanup(hMainWnd);

	return 0;
}




























void MINI_INPUT_GetInt(int *ps32Int, char *pMessage)
{
	QLOG(DBG, "%s", pMessage);
	scanf("%d", ps32Int);
}

void MINIGUI_TEST_mini()
{
	int s32Type;
	do {
		MINI_INPUT_GetInt(&s32Type, "选择需要测试的功能 :\n\
1(Hello World)\n\
2(对话框)\n\
3.(预定义控件实现简单输入对话框)\n\
4.滚动条\n\
5.图片显示、滚动条控件\n\
6.列表、滚动条控件\n\
7.独立滚动条\n\
8.键盘\n\
9.软键盘\n\
10.软键盘手写\n\
11.鼠标\n\
12.按钮\n\
13.列表\n\
14.进度条\n\
15.月历\n\
16.组合框、下拉列表\n\
17.图标控件\n\
18.属性表\n\
19.控件\n\
20.编辑框\n\
21.键盘KT\n\
22.软键盘选择\n\
23.主界面模拟\n\
0.退出\n:");

		if(s32Type == 1) {
			MINI_TEST_HelloWorld();
		} else if(s32Type == 2) {
			MINI_TEST_DialogBoxIndirectParam();
		} else if(s32Type == 3) {
			MINI_TEST_InputLenDialogBox();
		} else if(s32Type == 4) {
			MINI_TEST_ScrollWin();
		} else if(s32Type == 5) {
			MINI_TEST_ImageViewer();
		} else if(s32Type == 6) {
			MINI_TEST_Book();
		} else if(s32Type == 7) {
			MINI_TEST_Scrollbar();
		} else if(s32Type == 8) {
			MINI_TEST_Key();
		} else if(s32Type == 9) {
			MINI_TEST_SoftKey();
			//MINIGUI_TEST_SoftKey();
		} else if(s32Type == 10) {
			MINI_TEST_SoftKeyHandWrite();
		} else if(s32Type == 11) {
			MINI_TEST_Painter();
		}else if(s32Type == 12) {
			MINI_TEST_BUTTON();
		} else if(s32Type == 13) {
			MINI_TEST_list();
		} else if(s32Type == 14) {
			MINI_TEST_ProgressBar();
		} else if(s32Type == 15) {
			MINI_TEST_Month();
		} else if(s32Type == 16) {
			MINI_TEST_CommonBobox();
		} else if(s32Type == 17) {
			MINI_TEST_SpriteIcon();
		} else if(s32Type == 18) {
			MINI_TEST_PropSheet();
		} else if(s32Type == 19) {
			MINI_TEST_TimerEditor();
		} else if(s32Type == 20) {
			MINI_TEST_Edit();
		} else if(s32Type == 21) {
			MINI_TEST_Kt();
		} else if(s32Type == 22) {
			MINI_TEST_Switch();
		} else if(s32Type == 23) {
			MINI_TEST_MainWindow();
		} else if(s32Type == 0) {
			return;
		}else {
			SLOG(DBG, "无效的输入参数!!!!\n");
			s32Type = 0;
		}
	} while(0);

}


